1/19
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No study sessions yet.
What is the order for SQL Clause.
ORDER BY
GROUP BY
HAVING
WHERE
FROM
SELECT
SELECT
FROM
WHERE
GROUP BY
HAVING
ORDER BY
What can be in SELECT clause
Column names, expressions, aliases, aggregates (if GROUP BY is used)
What cannot be in SELECT clause
Filters, conditions, aggregates without GROUP BY
What can be in WHERE clause
Row-level filters, comparisons, logical operators (AND, OR, NOT)
What cannot be in WHERE clause
Aggregate functions like AVG(), COUNT(), SUM()
What can be in GROUP BY clause
Columns used in SELECT or aggregate functions
What cannot be in GROUP BY clause
Aliases, expressions not in SELECT, DESC keyword
What can be in HAVING clause
Conditions on aggregated results (e.g., HAVING AVG(price) > 100)
What cannot be in HAVING clause
Non-aggregated filters (use WHERE instead)
What can be in ORDER BY clause
Column names, aliases, expressions, ASC/DESC
What cannot be in ORDER BY clause
Grouping logic or filters
Correct SQL clause order
SELECT → FROM → WHERE → GROUP BY → HAVING → ORDER BY
GROUP BY vs ORDER BY – what are the key difference
GROUP BY groups rows; ORDER BY sorts rows or groups
GROUP BY vs ORDER BY – are they independence
They are independent; one does not require the other
Can you use ORDER BY without GROUP BY?
Yes – ORDER BY works on rows even without grouping
Can you use GROUP BY without ORDER BY?
Yes – GROUP BY groups data regardless of sort order
Sorting by multiple fields what do you use
Use: ORDER BY field1 ASC, field2 DESC
GROUP BY has nothing to do with ordering why?
It only groups rows for aggregation
ORDER BY has no impact on grouping why?
It only sorts rows or groups
Can GROUP BY and ORDER BY appear together?
Yes – they are independent and can be used together or separately