# SQL commands sequence

**URL:** <https://forum.freecodecamp.org/t/sql-commands-sequence/216848>\
**Category:** General\
**Created:** [August 11, 2018, 4:18pm UTC](https://forum.freecodecamp.org/t/sql-commands-sequence/216848 "2018-08-11T16:18:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![zhouxiang19910319](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/zhouxiang19910319/32/98849_2.png) [@zhouxiang19910319](https://forum.freecodecamp.org/u/zhouxiang19910319)\
**Post date:** [August 11, 2018, 4:18pm UTC](https://forum.freecodecamp.org/t/sql-commands-sequence/216848/1 "2018-08-11T16:18:00Z")

</div>

I knew that in SQL generally we write statements like this :

/\* after creating the table \*/

`SELECT something FROM table_name WHERE something something`

or

`SELECT something FROM table_name HAVING something something`

The question I wanna ask is does it matter where do I put `GROUP BY`?

Can I add it at the end like this :

`SELECT something FROM table_name WHERE something something GROUP BY something`

Or I should add it in the middle?

`SELECT something FROM table_name GROUP BY something WHERE something something`

Does it really matter?

Thanks in advance.

@camperextraordinaire

---

<div class="post-metadata">

**Author:** ![hbar1st](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/hbar1st/32/372649_2.png) [@hbar1st](https://forum.freecodecamp.org/u/hbar1st)\
**Post date:** [August 11, 2018, 5:19pm UTC](https://forum.freecodecamp.org/t/sql-commands-sequence/216848/2 "2018-08-11T17:19:09Z")

</div>

I believe ‘where’ has to come before ‘group’. But that is an easy thing to test, so why not just try?

here’s a reference I found on this:

> **[SQL Query Order of Operations](https://www.bennadel.com/blog/70-sql-query-order-of-operations.htm)**
>
> Ben Nadel's web development blog on ColdFusion, jQuery, HTML5, AJAX, SQL, and all aspects of web application development.

---

<div class="post-metadata">

**Author:** ![sorinr](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/sorinr/32/87166_2.png) [@sorinr](https://forum.freecodecamp.org/u/sorinr)\
**Post date:** [August 11, 2018, 5:25pm UTC](https://forum.freecodecamp.org/t/sql-commands-sequence/216848/4 "2018-08-11T17:25:47Z")

</div>

Think this [article](https://sqlwithmanoj.com/2015/05/23/sql-basics-difference-between-where-group-by-and-having-clause/) may help you understand the diffs between where, having and group by in sql

---

<div class="post-metadata">

**Author:** ![zhouxiang19910319](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/zhouxiang19910319/32/98849_2.png) [@zhouxiang19910319](https://forum.freecodecamp.org/u/zhouxiang19910319)\
**Post date:** [August 13, 2018, 2:25pm UTC](https://forum.freecodecamp.org/t/sql-commands-sequence/216848/5 "2018-08-13T14:25:18Z")

</div>

so , in summary I can explain the syntax like this:

```auto
/*general rules*/

SELECT ...
FROM...
WHERE...
GROUP BY...
HAVING...

```
