SQL Store selling all titles
SQL
Download (.zip)
INSERT stores (stor_id, stor_name, stor_address, city, state, zip) VALUES ('9999', 'WE SUPPLY IT ALL', 'One Main St', 'Poulsbo', 'WA', '98370')
-- By using a combination of hard-coded values and selecting every -- title, generate a sales row for every title INSERT sales (stor_id, title_id, ord_num, ord_date, qty, payterms) SELECT '9999', title_id, 'PHONY1', GETDATE(), 10, 'Net 60' FROM titles
-- Find stores that supply every title SELECT ST.stor_id, ST.stor_name, ST.city, ST.state FROM stores ST -- WHERE NOT EXISTS -- (SELECT * FROM titles T1 -- WHERE NOT EXISTS -- (SELECT * -- FROM titles T2 JOIN sales S ON (T2.title_id=S.title_id) -- WHERE T2.title_id=T1.title_id AND ST.stor_id=S.stor_id) -- )
WHERE NOT EXISTS (SELECT * FROM titles T1 WHERE NOT EXISTS (SELECT * FROM sales S WHERE S.title_id=T1.title_id AND ST.stor_id=S.stor_id) )
|