polaryeti Posted October 27, 2025 Share Posted October 27, 2025 This is a sample database. The answer(relational algebra query) is:(I am converting those queries to SQL) So it is first finding all suppliers who supply P2 from shipments table Then it finds all suppliers who do not supply p2. Then it joins all those suppliers who do not supply p2 with suppliers table? What does this gives us? A join with those who do not supply part p2? Now, finally, it subtracts that joined result-thosee who supply p2. And that should bring the names of suppliers who do not supply p2. I did not quite get how join helped here? Can anyone describe this? Quote Link to comment https://forums.phpfreaks.com/topic/332298-get-supplier-names-for-suppliers-who-do-not-supply-part-p2/ Share on other sites More sharing options...
polaryeti Posted October 27, 2025 Author Share Posted October 27, 2025 Personally I would frame a query like this select supplier_name from suppliers join shipments (select supplier_number from shipments where part_number!='P2') DIFFERENCE (select supplier_number from shipments where part_number='P2' ) But obviously there are lots of mistakes here since I am not aware of what difference operator is in postgresql,how can I rename a table Quote Link to comment https://forums.phpfreaks.com/topic/332298-get-supplier-names-for-suppliers-who-do-not-supply-part-p2/#findComment-1661719 Share on other sites More sharing options...
Barand Posted October 27, 2025 Share Posted October 27, 2025 To find records where there is no match in another table you use a LEFT JOIN. Data from the the second table where there is no match will contain NULL values. SELECT s.name FROM supplier s LEFT JOIN shipment sh ON s.suppid = sh.suppid AND sh.prodid = 'P2' WHERE sh.suppid IS NULL 1 Quote Link to comment https://forums.phpfreaks.com/topic/332298-get-supplier-names-for-suppliers-who-do-not-supply-part-p2/#findComment-1661722 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.