SQL
Find Records Unique to One Table
Identify rows present in the first table but completely missing from the second table, using a LEFT JOIN with a NULL check to find unmatched records.
SELECT u.id, u.username
FROM users u
LEFT JOIN orders o ON u.id = o.user_id
WHERE o.user_id IS NULL;
How it works: This snippet finds records in the `users` table that do not have any corresponding entries in the `orders` table (e.g., users who have never placed an order). A `LEFT JOIN` includes all rows from the left table (`users`) and matching rows from the right table (`orders`). When there's no match, the columns from the right table will be `NULL`, which is then used in the `WHERE` clause to filter for unique records.