JOIN - Combining Tables1 / 10
In SQL, you can use a JOIN to combine different tables. You join them by a common column, like the customer_id in both tables below.
We can match the customer_id in the orders with the customer_id in the customers table to combine the tables and get a result that you couldn't get from either table alone. Try:
We can match the customer_id in the orders with the customer_id in the customers table to combine the tables and get a result that you couldn't get from either table alone. Try:
SELECT customer_name, order_total FROM customers INNER JOIN orders ON customers.customer_id = orders.customer_id;| customer_id | customer_name | country |
|---|---|---|
| 1 | Alice | USA |
| 2 | Bob | Canada |
| 3 | Carlos | Spain |
| 4 | Diana | UK |
| order_id | customer_id | order_total |
|---|---|---|
| 101 | 1 | 45.99 |
| 102 | 1 | 89.50 |
| 103 | 2 | 22.00 |
| 104 | 5 | 100.00 |
Ctrl+Enter to submit
JOIN - Combining Tables - Free SQL Practice Online
Practise JOIN - Combining Tables with 10 free, interactive SQL exercises. You type real queries into your browser and get instant feedback on every answer - no database setup, no install, and no signup. It is a fast, hands-on way to learn SQL online and build query skills you can use at work.