USING — Compact Equality Join on Same-Named Columns
Join employees to departments with USING(department_id) and return the requested directory columns.
- Joins
- Sorting
Exercise brief
Understand the request
Data platform reviewer A portability review compares compact shared-key syntax with explicit ON predicates.
When the join key has the SAME name on both sides, the USING(col) clause is a compact alternative to ON. Re-do Q1 (employees + departments) using JOIN ... USING(department_id). Return department_id, employee_id, first_name, last_name, department_name — ordered by employee_id.
Return
- Return department_id, employee_id, first_name, last_name, department_name in this exact left-to-right order.
Constraints
- Use JOIN ... USING(department_id).
- Do not use NATURAL JOIN because schema changes could alter its predicate silently.
Data you will use
Review the relevant tables before deciding how to join, filter, or aggregate them.
employees
employee_idINTEGERfirst_nameVARCHAR(50)last_nameVARCHAR(50)department_idINTEGER
departments
department_idINTEGERdepartment_nameVARCHAR(50)
Hints, when you need them
Open one clue at a time so you still do the reasoning.
Hint 1
USING (col) is shorthand for ON left.col = right.col when both sides spell the column the same.
Hint 2
Inside the SELECT, reference the USING column WITHOUT a table prefix — there is only one of it after the join.
Hint 3
NATURAL JOIN goes further (joins on EVERY same-named column) but is dangerous — schema changes silently change the join.
Verified SQL answer
Attempt the problem first, then compare structure and reasoning—not just syntax.
Reveal solution and explanation
SELECT department_id, e.employee_id, e.first_name, e.last_name, d.department_name FROM employees e INNER JOIN departments d USING (department_id) ORDER BY e.employee_id;Why this works
USING is purely syntactic sugar for ON, with one twist: the joined column appears once (and unqualified) in the result. PostgreSQL, SQLite, MySQL all support it. SQL Server does NOT — use ON there.
Success check
The result matches the equality join while demonstrating shared-key USING syntax.
Expected result
Use this output to verify values, aliases, ordering, and row count.
| department_id | employee_id | first_name | last_name | department_name |
|---|---|---|---|---|
| 10 | 100 | John | Smith | IT |
| 10 | 101 | Alice | Johnson | IT |
| 10 | 102 | Bob | Wilson | IT |
| 20 | 103 | Carol | Davis | HR |
| 30 | 104 | David | Brown | Finance |
| 40 | 105 | Emma | Taylor | Marketing |
| 40 | 106 | Frank | Green | Marketing |
| 10 | 107 | Grace | White | IT |
| 20 | 108 | Henry | Clark | HR |
| 30 | 109 | Ivy | Martinez | Finance |
Learn the concepts behind this answer
Strengthen your understanding with these targeted learning topics:
Continue practicing
Build the next SQL skill
Self Joins & Hierarchical Queries
Query organization charts, trees, and parent-child relationships.
SQL Subqueries
Practice scalar, derived-table, correlated, EXISTS, NULL-safe anti-subquery, quantified, and row-subquery patterns.
SQL Aggregations
Build reliable SQL metrics from aggregate functions through grain, fan-out, weighted ratios, rollups, percentiles, and approximate counts.
Open the interactive workspace and practice across SQL topics.