Problem 1.
Recyclable and Low Fat Products
Find the ids of products that are both low fat and recyclable.
Input Table(s):
product_id low_fats recyclable
1 Y N
2 Y Y
3 N Y
Expected Output:
product_id
2
SQL Query:
SELECT product_id
FROM Products
WHERE low_fats = 'Y' AND recyclable = 'Y';
Explanation:
We filter rows where both conditions hold true using `WHERE` with `AND`.
Problem 2. Find Customer Referee
Find the names of customers whose referee_id is not equal to 2.
Input Table(s):
id name referee_id
1 Will
2 Jane
3 Alex 2
4 Bill
5 Zack 1
6 Mark 2
Expected Output:
name
Will
Jane
Bill
Zack
SQL Query:
SELECT name
FROM Customer
WHERE referee_id IS NULL OR referee_id != 2;
Explanation:
We must use `IS NULL` instead of `= 'null'`. This query finds customers without a referee or with a
referee different from 2.