Exercise · SQL & Querying
Predict, then run it
Predict the output
shelf(item, n) = (X,1),(Y,2). loans(item, n) = (Y,2),(Z,3). Reconcile the two lists — each item with its side-status:
SELECT COALESCE(s.item, l.item) AS item, CASE WHEN s.item IS NULL THEN 'b_only' WHEN l.item IS NULL THEN 'a_only' WHEN s.n IS DISTINCT FROM l.n THEN 'diff' ELSE 'ok' END AS status FROM shelf s FULL OUTER JOIN loans l ON l.item = s.item ORDER BY item;
Predict the exact output.