Cross join two tables and return every row pairing in a fixed order
Company: AMD
Role: Data Scientist
Category: Data Manipulation (SQL/Python)
Difficulty: easy
Interview Round: Other
Overview: Write a SQL query that returns the Cartesian product of two tables, pairing every row of one with every row of the other and sorting by both ids. It tests cross join syntax, aliasing two tables that share a column name, and producing a deterministic row order.
Tables
tablea(id INTEGER, name VARCHAR(50))
tableb(id INTEGER, color VARCHAR(50))
Hints
- Both tables have an `id` column. Decide how the query will tell them apart in the select list and in the ordering.
- Check your row count: m rows in `tablea` and n rows in `tableb` should give exactly m × n rows, even when no `id` value appears in both tables.