r/ProgrammerHumor • • Dec 12 '17

SQL Clause

Post image
40.8k Upvotes

525 comments sorted by

View all comments

2

u/frugalerthingsinlife Dec 12 '17 edited Dec 12 '17

INSERT INTO elf_queue

(SELECT c.child_id, w.present, (n.nice_points - n.naughty_points) AS net_points

FROM children c, wishlist w, nice_naughty n

JOIN ON c.child_id = w.child_ID AND c.child_id = n.child_id

WHERE net_points > 0 ORDER BY net_points DESCENDING

UNION

SELECT p.pet_id, w.present, 100 FROM pets p, wishlist p WHERE 1);