Multi-select
Status
Done
Here's a concise version to remember SQL execution with JOIN:
- FROM
- JOIN: Combine tables (e.g., join customers and orders).
- WHERE: Filter rows (e.g., orders over 50).
- GROUP BY: Group the filtered data.
- HAVING: Filter groups (e.g., customers with >2 orders).
- SELECT: Choose columns to display.
- DISTINCT: Remove duplicate rows if needed.
- ORDER BY: Sort the results.
- LIMIT: Restrict the number of rows returned.

SELECT Distinct customer_id, COUNT(order_id) AS total_orders
FROM customers
JOIN orders ON customers.customer_id = orders.customer_id
WHERE orders.amount > 50
GROUP BY customer_id
HAVING COUNT(order_id) > 2
ORDER BY total_orders DESC
LIMIT 5;
Here's a concise table that summarizes the SQL execution order with JOIN, along with the mnemonic for quick recall:
Step | Clause | Purpose |
1 | FROM & JOIN | Retrieve data and combine tables via JOIN. |
2 | WHERE | Filter rows before any aggregation. |
3 | GROUP BY | Group rows for aggregation functions. |
4 | HAVING | Filter the groups after aggregation. |
5 | SELECT | Choose the columns to display. |
6 | DISTINCT | Remove duplicate rows, if necessary. |
7 | ORDER BY | Sort the final result set. |
8 | LIMIT | Limit the number of rows returned. |
Mnemonic:
Funke Wears Green Hart, Speaking Distinctly Over Lunch
- Funke: FROM
- Wears: WHERE
- Green: GROUP BY
- Hart: HAVING
- Speaking: SELECT
- Distinctly: DISTINCT
- Over: ORDER BY
- Lunch: LIMIT