Hint and exampleShowHide
Compare two columns of the same row, then use DISTINCT to remove repeats and ORDER BY to sort the answer.
Example: payments(payer_id, payee_id, amount) — who paid themselves?
payer_id | payee_id | amount
7 | 7 | 100
3 | 5 | 50
7 | 7 | 20
2 | 2 | 10
SELECT DISTINCT payer_id AS id
FROM payments
WHERE payer_id = payee_id
ORDER BY id; -- returns 2, 7
More in SQL: SELECT & Filtering
| # | Problem | Platform | Difficulty | Open | 1st1st Visit | 2nd2nd Visit | RevRevise |
|---|---|---|---|---|---|---|---|
| 1 | Recyclable and Low Fat Products | LeetCode | Easy | Solve Recyclable and Low Fat Products on LeetCode (opens in a new tab) | |||
| 2 | Big Countries | LeetCode | Easy | Solve Big Countries on LeetCode (opens in a new tab) | |||
| 3 | Article Views I | LeetCode | Easy | Solve Article Views I on LeetCode (opens in a new tab) | |||
| 4 | Not Boring Movies | LeetCode | Easy | Solve Not Boring Movies on LeetCode (opens in a new tab) | |||
| 5 | Find Customer Referee | LeetCode | Easy | Solve Find Customer Referee on LeetCode (opens in a new tab) |