Joining table data
Preparation:
Peer instruction
1. What does the following query obtain?
SELECT *
FROM employees
WHERE employee_number = "NULL"A) Retrieves all employees with an employee number called NULL
B) Retrieves all employees without an employee number
C) Retrieves all employees except employees without an employee number
D) Syntax Error
2. What does the following query obtain?
SELECT *
FROM imdb
WHERE duration > 0
AND duration IS NOT NULL;A) Retrieves all movies from IMDB with a duration greater than zero and all NULL values
B) Retrieves all movies from IMDB with a duration less than 0
C) Retrieves all movies from IMDB with a duration greater than zero and without NULL values
D) Retrieves all movies from IMDB with a duration greater than zero or without NULL values
Exercise 1: Individuelt
Join the two tables by department_number and display all columns.
Retrieve all the employees from the Accounting department.
3 Rows returned
Retrieve only the names of all employees from operations and research.
5 Rows returned
Retrieve all employees who work in departments located in Chicago.
6 Rows returned
Retrieve all names of all employees from Chicago that has a commission.
3 or 4 rows returned (depending on interpretation)
Show employees who report to the manager named 'BLAKE'.
5 Rows returned - Allen, Ward, Martin, Turner, James
Advanced (Optional)
Retrieve the names of employees who earn more than their manager, along with their manager’s name and both salaries.
2 Rows returned: Scott & Ford
Retrieve all data from employees and their department except clerks or employees from Chicago with a commission.
6 or 7 Rows returned - depending on interpretation: Clark, King, Jones, Scott, Ford, Blake, (Turner)
Retrieve the names of all non-salesmen whose department location is different from their manager’s department location.
2 Rows returned: Jones & Blake
Import dataset to database:
Exercise 2: Par-øvelser
Import the dataset: https://github.com/behu-kea/dat20-classes/blob/master/SQL/assets/coffee-database.sql

Exercises
Notice that the 'gender' datatype is an ENUM
Research: What is an enum? How does it work?
Select the order_table id and the customers phone number for all orders of product id 3
4 Rows returned: Order ID 3, 6 ,12, 13
Select product names and order time for the espresso coffees sold between January 15th 2021 and February 14th 2021
3 Rows returned: 2021-02-05, 2021-02-06, 2021-02-06
Select the product name and price and order time for all orders from females in February 2021
4 Rows returned: order_table_id: 4, 9,10, 13
From the products table, select the name for all products that have a price greater than 30 or a coffee origin of Sri Lanka
5 Rows returned: Latte, Cappuchino, Black, Te, Black Exotic
From the products table, select the name and price of all produts with a coffee origin equal to Colombia or Sverige. Ordered by name from A-Z
4 Rows returned: Cappuchino, Espresso, Latte, Saft
Last updated