INNER JOIN

SELECT with an INNER JOIN

In this exercise we will query the employees table using an INNER JOIN with the orders table.

SELECT DISTINCT employees.employee_id,
employees.last_name,
employees.first_name,
employees.title
FROM employees
INNER JOIN orders ON employees.employee_id = orders.employee_id;
Run in terminal

The query should return 9 rows.

SELECT with an INNER JOIN and ORDER BY

In this exercise we will query the employees table by using an INNER JOIN with the orders table and order the results by product_id in a descending order.

SELECT DISTINCT products.product_id,
products.product_name,
order_details.unit_price
FROM products
INNER JOIN order_details ON products.product_id = order_details.product_id
ORDER BY products.product_id DESC;
Run in terminal

The query should return 156 rows.

SELECT with an INNER JOIN and WHERE clause

In this exercise we will query the products table by using an INNER JOIN with the order_details table where the product_id equals 2.

SELECT DISTINCT products.product_id,
products.product_name,
order_details.order_id
FROM products
INNER JOIN order_details ON products.product_id = order_details.product_id
WHERE products.product_id = 2;
Run in terminal

The query should return 44 rows.

SELECT with an INNER JOIN and three tables

In this exercise we will query the orders table by using an INNER JOIN with the customers and _employees_table.

SELECT customers.company_name,
employees.first_name,
orders.order_id
FROM orders
INNER JOIN customers ON customers.customer_id = orders.customer_id
INNER JOIN employees ON employees.employee_id = orders.employee_id;
Run in terminal

The query should return 830 rows.