Exercise · SQL & Querying
Predict, then run it
Predict the output
stock(item, qty, donor_id) = (rice,3,1),(beans,2,2). donors(donor_id, name) has donor 1 double-entered: (1,Ada),(1,Ada),(2,Ben). Total qty, deduping the donor side first:
SELECT SUM(s.qty) AS total FROM stock s JOIN (SELECT DISTINCT donor_id, name FROM donors) d ON d.donor_id = s.donor_id;
Predict the exact output.