LC 183 & LC 584 & LC 595 & LC 1757


The following intro-level SQL problems are about ‘selecting (WHERE)’.

LeetCode 183

Customers Who Never Order (Easy) [link]

Using WHERE.

SELECT C.name AS Customers
FROM Customers C
WHERE C.id NOT IN (
    SELECT customerId FROM Orders
);

Using LEFT JOIN.

SELECT C.name AS Customers
FROM Customers C
LEFT JOIN Orders O
ON C.id = O.customerId
WHERE O.id IS NULL;

LeetCode 584

Find Customer Referee (Easy) [link]

SELECT name
FROM Customer
WHERE referee_id != 2 OR referee_id IS NULL;

Alternative method to deal with null values

SELECT name
FROM Customer
WHERE IFNULL(referee_id, 0) != 2;

LeetCode 595

Big Countries (Easy) [link]

SELECT name, population, area
FROM World
WHERE population >= 25000000 OR area >= 3000000;

LeetCode 1757

Recyclable and Low Fat Products (Easy) [link]

SELECT product_id
FROM Products
WHERE low_fats = 'Y' AND recyclable = 'Y';

  TOC