Complete the SQL query to select all columns from two tables using a Cartesian product.
SELECT * FROM employees [1] departments;The CROSS JOIN keyword produces the Cartesian product of the two tables, combining every row of the first table with every row of the second table.
Complete the SQL query to join two tables on a matching column.
SELECT * FROM orders [1] customers ON orders.customer_id = customers.id;The INNER JOIN keyword returns rows when there is a match in both tables based on the join condition.
Fix the error in the SQL join query by completing the missing keyword.
SELECT * FROM products [1] ON products.category_id = categories.id;The INNER JOIN keyword is required here to join the tables based on the condition after ON. Using just JOIN is ambiguous in some SQL dialects.
Fill both blanks to create a query that selects employee names and department names using an INNER JOIN.
SELECT employees.name, departments.name FROM employees [1] departments [2] employees.department_id = departments.id;
The INNER JOIN keyword joins the tables, and the ON keyword specifies the join condition.
Fill all three blanks to write a query that selects all orders and their customers, including orders without customers, using a LEFT JOIN.
SELECT orders.id, customers.name FROM orders [1] customers [2] orders.customer_id = customers.id [3];
The LEFT JOIN returns all orders even if there is no matching customer. The ON specifies the join condition. ORDER BY sorts the results by order ID.