GROUP BY

The WHERE clause is not needed with GROUP BY clauses.
The columns being selected must be included in the GROUP BY CLAUSE


SELECT NAME
FROM
col$
WHERE
COL# = 1
GROUP BY NAME;

so if I wanted to include two columns: name, age. I would have have to include them in the GROUP BY clause.

SELECT name, age
FROM table_name
GROUP BY name, table_name

Again, the WHERE clause is not necessary, unless you wanted to filter by a particular object..

GROUP BY With a renamed Column name.

Where doing the filtering, the WHERE clause must call upon the original column name
Here is an example,

# rename a column and group

SELECT employment_date AS recent_dates, employee_name
FROM employee
GROUP BY employment_date

In logical terms, when the computer is processing a query, it goes in the following sequence:
starts at FROM –> WHERE –> GROUP BY –> HAVING –> ORDER BY –> SELECT.
As you can see, the select is the last final clause in the query sequence.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top