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.titleFROM employeesINNER 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_priceFROM productsINNER JOIN order_details ON products.product_id = order_details.product_idORDER 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_idFROM productsINNER JOIN order_details ON products.product_id = order_details.product_idWHERE 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_idFROM ordersINNER JOIN customers ON customers.customer_id = orders.customer_idINNER JOIN employees ON employees.employee_id = orders.employee_id;Run in terminal
The query should return 830 rows.