INNER JOIN, Aliases and USING in MySQL
All lessons
- INNER JOIN, Aliases and USING in MySQLFree
- LEFT JOIN, Filters in ON and the Anti-Join Locked
- Joining Three Tables: Lines, Products and Orders Locked
- Self Joins: Employees and Their Managers Locked
- Join Fan-Out: Why Totals Grow After a Join Locked
- Views: Saving a Join Under a Name Locked
- Updatable Views and WITH CHECK OPTION Locked
- Stored Procedures with IN Parameters Locked
- OUT and INOUT Parameters, SELECT ... INTO Locked
- IF, ELSEIF and CASE in Procedures Locked
- Loops in Procedures: WHILE, REPEAT and LOOP Locked
- Stored Functions: DETERMINISTIC, RETURNS and Rounding Locked
- Cursors and the NOT FOUND Handler Locked
- SIGNAL, SQLSTATE 45000 and Error Handlers Locked
- BEFORE INSERT Triggers: Changing NEW Locked
- AFTER Triggers: Stock Updates and Alerts Locked
- Transactions, COMMIT, ROLLBACK and Savepoints Locked
- Indexes for Joins and Foreign Keys Locked
- Schema Design: Normalization and Foreign Key Actions Locked
- Capstone: Procedure, Trigger and View in One Order Run Locked
You are not signed in — the lab works, but your progress is not saved. Sign up
Read first
The SQL
-- Query 1
SELECT o.order_id, c.name, o.amount
FROM orders AS o
INNER JOIN customers AS c
ON c.customer_id = o.customer_id
WHERE c.city = 'Basel';
-- Query 2
SELECT c.city, SUM(o.amount) AS revenue
FROM orders AS o
JOIN customers AS c USING (customer_id)
WHERE o.status <> 'Cancelled'
GROUP BY c.city
ORDER BY revenue DESC;Give every table a short alias and prefix every column with it (o.amount, c.city). With two tables in the query, an unqualified column such as customer_id would be ambiguous (error 1052).
Loading the lab…