N020-M3 Tier 2 · Core SQL · medium hr · Helix Systems

Return the employee name and department name for every Engineering-employee × department combination

Part of CROSS JOIN in SQL

The problem

A training coordinator at Helix Systems needs every possible pairing of an Engineering-department employee (department_id = 1) with every company department for a cross-functional assignment matrix.

Write a query to return the employee name and department name for every Engineering-employee × department combination.

Assumptions:

  • The employees table contains every active and former employee at Helix Systems.
  • The departments table contains every department; Engineering is department_id = 1.
  • Each Engineering employee should appear once paired with every department, including Engineering itself.

Output:

  • One row per Engineering-employee × department combination, with columns employee_name and department_name.
Schema · hr 4 tables
departments
id integer
name text
location text
budget numeric
salaries
id integer
employee_id integer
amount numeric
effective_date date
end_date? date
employees
id integer
name text
email text
department_id integer
manager_id? integer
hire_date date
title text
is_active boolean
job_history
id integer
employee_id integer
title text
department_id integer
start_date date
end_date? date

Run previews · Check grades

Write a query, then run it to see results here.

Worked solution Try it yourself first
Solution query
SELECT
  e.name AS employee_name,
  d.name AS department_name
FROM
  employees e
  CROSS JOIN departments d
WHERE
  e.department_id = 1

The shape

WHERE e.department_id = 1 narrows employees to the Engineering cohort, and CROSS JOIN departments d pairs each Engineering employee with every department in the company — including Engineering itself. The result is the cross-functional assignment matrix the training coordinator needs.

Clause by clause

  • FROM employees e CROSS JOIN departments d is the unconditional pairing. Every row in employees combines with every row in departments.
  • WHERE e.department_id = 1 restricts the left side to Engineering employees. The integer 1 is the literal value of department_id for Engineering; the filter reads the employee's own department from the employees table, not from the joined departments row.
  • e.name AS employee_name pulls the employee's name from the left side. d.name AS department_name pulls the department name from the right. Both source tables have a name column, so the table aliases are what tell PostgreSQL which one each reference resolves to.

Why this and not INNER JOIN ... ON e.department_id = d.id

An INNER JOIN on department_id would return one row per Engineering employee paired with the Engineering department only — the existing assignment, nothing more. The matrix the coordinator is building needs every Engineering employee paired with every department, including the ones they could rotate into. CROSS JOIN produces that full grid by not matching on the department relationship at all. The Engineering filter is on the employee side; the department side is left wide open.

You practiced a CROSS JOIN where one side has been pre-filtered to a cohort. The shape generalises: any time one side is a cohort and the other is a complete catalogue, WHERE cohort_filter + CROSS JOIN produces the cohort-by-catalogue grid.

How you actually get good at SQL

Reading explains SQL. Writing it, over and over with instant feedback, is what makes you fluent.

That's the whole SQLMaxx loop: 600+ real problems, instant AI feedback, mastery you can actually see, and spaced review that won't let you forget.

A stack of SQL practice problem cards, the top card showing an employees table.
615 problems · 66 concepts

Real problems. Not toy examples.

615 hand-built problems spanning all 66 concepts, from basic SELECTs to window functions, built on real schemas and real business questions, the kind you'll actually get asked on the job. Enough reps to make SQL automatic.

A retro computer showing a SQL query marked correct with a green checkmark.
Instant AI feedback

Write a query. Know if it's right in one second.

No copying an answer and hoping it clicked. The AI grader checks your real query against real data, catches exactly what's wrong, and explains the fix in plain English, like a senior analyst reading over your shoulder on every problem.

A circular mastery progress dial filling from blue to green, the SQLMaxx diamond at its center.
Mastery tracking

Stop guessing whether you actually know it.

SQLMaxx tracks every concept and shows you what you've mastered and what's still shaky. Your skills fill in one concept at a time, so 'I think I get joins' becomes something you can prove.

A SQL query editor circled by a blue return arrow with a clock, scheduled to come back for review.
Spaced review

Learn it once. Keep it for good.

Most of what you learn this week fades by next week. So when a concept comes due for review, SQLMaxx hands you a fresh problem to solve from a blank editor, not a flashcard to re-read. A research-backed spaced-repetition algorithm (FSRS) times each return for right before you'd forget, so your SQL is still there months later, when the interview or the job actually needs it.

Practice, feedback, mastery, review. That's the loop that turns reading into real skill.

Start free

No account, no credit card. Start solving in under a minute.