The tables below come from a small company database, where each employee belongs to at most one department.
departments
dept_id
name
10
Sales
20
Research
30
Legal
40
Support
employees
emp_id
1
Ava
2
Raj
3
Kim
4
Leo
5
Zoe
NULL
6
Sam
How many rows does the following query return? Give your answer as a whole number.
SELECT d.name AS department, e.name AS employee FROM departments d LEFT JOIN employees e ON d.dept_id = e.dept_id;
Unlock full course notes by signing up
Row counts for every join type
An online shop imported its reviews table from an old system without a foreign-key constraint, so one review refers to a product that no longer exists.
products
reviews
Reading employee and supervisor aliases
A company stores employees and their immediate supervisors in the following Staff table. The column staff_id uniquely identifies each employee, and manager_id contains that employee's supervisor's staff_id. NULL indicates no supervisor.
The company runs this query:
Complete the three output rows below in the order returned by the query. Enter each person's name exactly as shown in the source table.
General properties of equality joins
Two tables A and B are joined with the equality condition A.k = B.k on a column k that exists in both tables, and no WHERE clause is applied. Select every statement that is true for all such tables.
Diagnosing inflated totals across two detail tables
An online retailer stores orders, ordered quantities and payments in three tables. The tables below contain all records relevant to this report. Each line_id and each payment_id is unique. Payments apply to whole orders rather than individual order lines, and all monetary amounts are in Canadian dollars (CAD).
Orders
OrderLines