Complete the code to select all columns from both tables where the primary key matches the foreign key.
SELECT * FROM orders JOIN customers ON orders.customer_id = customers.[1];The foreign key orders.customer_id matches the primary key customers.id. So, we join on customers.id.
Complete the code to join employees and departments on the foreign key department_id.
SELECT employees.name, departments.name FROM employees JOIN departments ON employees.[1] = departments.id;employees instead of the foreign key.The foreign key in employees is department_id, which matches the primary key departments.id.
Fix the error in the join condition to correctly join sales and products.
SELECT * FROM sales JOIN products ON sales.product_id = products.[1];product_name.The foreign key sales.product_id should match the primary key products.id. Joining on other columns causes errors or wrong results.
Fill both blanks to join invoices and clients on the correct keys.
SELECT invoices.id, clients.name FROM invoices JOIN clients ON invoices.[1] = clients.[2];
name.The foreign key invoices.client_id matches the primary key clients.id. This is the correct join condition.
Fill all three blanks to join payments and orders and select payment amount and order date.
SELECT payments.amount, orders.[1] FROM payments JOIN orders ON payments.[2] = orders.[3];
orders.The foreign key payments.order_id matches the primary key orders.id. We select orders.order_date to see when the order was made.