Some tricky SQL examples:
SELECT MAX(salary)
FROM employees
WHERE salary < (SELECT MAX(salary) FROM employees);
At first glance, it's pretty easy to get tripped up by this SQL. What should it return?
How about something like this:
SELECT name, salary FROM employees
WHERE salary IN (
SELECT salary
FROM employees
GROUP BY salary
HAVING COUNT(*) > 1
);
And finally,
SELECT manager_id
FROM employees
WHERE manager_id NOT IN (SELECT DISTINCT manager_id FROM employees WHERE manager_id IS NOT NULL);
What is our expected result?