limok Posted June 8, 2017 Share Posted June 8, 2017 (edited) Hi I have the below data Order--Code--Fulfilled AAA--123--Yes BBB--123--Yes BBB--456--No CCC--456--Yes CCC--123--Yes From the above data how can I just get the orders that have been fully fulfilled (BBB has not been fulfilled so should be filtered out)? thanks! Link to comment https://www.neowin.net/forum/topic/1332970-sql-query-help/ Share on other sites More sharing options...
0 Slugsie Posted June 8, 2017 Share Posted June 8, 2017 (edited) SELECT * FROM <tablename> WHERE Fulfilled = 'Yes' *EDIT* Just noticed that BBB is 'partially' fulfilled, give me a minute on that one... Link to comment https://www.neowin.net/forum/topic/1332970-sql-query-help/#findComment-597919800 Share on other sites More sharing options...
0 limok Posted June 8, 2017 Author Share Posted June 8, 2017 Just now, Slugsie said: SELECT * FROM <tablename> WHERE Fulfilled = 'Yes' Not quite - this will also show me order BBB, which isn't fully fulfilled. Link to comment https://www.neowin.net/forum/topic/1332970-sql-query-help/#findComment-597919806 Share on other sites More sharing options...
0 Slugsie Posted June 8, 2017 Share Posted June 8, 2017 SELECT * FROM <tablename> WHERE Order NOT IN (SELECT Order FROM <tablename> WHERE Fulfilled = 'No') Something along those lines should work. +Zlip792 1 Share Link to comment https://www.neowin.net/forum/topic/1332970-sql-query-help/#findComment-597919816 Share on other sites More sharing options...
0 limok Posted June 8, 2017 Author Share Posted June 8, 2017 4 minutes ago, Slugsie said: SELECT * FROM <tablename> WHERE Order NOT IN (SELECT Order FROM <tablename> WHERE Fulfilled = 'No') Something along those lines should work. That will give the same result... Link to comment https://www.neowin.net/forum/topic/1332970-sql-query-help/#findComment-597919836 Share on other sites More sharing options...
0 Slugsie Posted June 8, 2017 Share Posted June 8, 2017 No it won't. Inner query finds all Orders that aren't fulfilled (which will include BBB), then outer query returns any orders that aren't on that list, so BBB will be excluded. limok 1 Share Link to comment https://www.neowin.net/forum/topic/1332970-sql-query-help/#findComment-597919840 Share on other sites More sharing options...
0 IceBreakerG Posted June 8, 2017 Share Posted June 8, 2017 Slugsie's response should work. In the sub-query, you'll get BBB because it hasn't been fully fulfilled. So it won't select BBB in the main query, just AAA and CCC. Link to comment https://www.neowin.net/forum/topic/1332970-sql-query-help/#findComment-597919842 Share on other sites More sharing options...
0 limok Posted June 8, 2017 Author Share Posted June 8, 2017 3 minutes ago, Slugsie said: No it won't. Inner query finds all Orders that aren't fulfilled (which will include BBB), then outer query returns any orders that aren't on that list, so BBB will be excluded. You're right it works! Thanks, Link to comment https://www.neowin.net/forum/topic/1332970-sql-query-help/#findComment-597919848 Share on other sites More sharing options...
0 Slugsie Posted June 8, 2017 Share Posted June 8, 2017 NP Link to comment https://www.neowin.net/forum/topic/1332970-sql-query-help/#findComment-597919852 Share on other sites More sharing options...
Question
limok
Hi
I have the below data
Order--Code--Fulfilled
AAA--123--Yes
BBB--123--Yes
BBB--456--No
CCC--456--Yes
CCC--123--Yes
From the above data how can I just get the orders that have been fully fulfilled (BBB has not been fulfilled so should be filtered out)?
thanks!
Link to comment
https://www.neowin.net/forum/topic/1332970-sql-query-help/Share on other sites
8 answers to this question
Recommended Posts