• 0

SQL Query Help


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 post
Share on other sites

8 answers to this question

Recommended Posts

  • 0
Slugsie

SELECT * FROM <tablename> WHERE Fulfilled = 'Yes'

*EDIT* Just noticed that BBB is 'partially' fulfilled, give me a minute on that one...

Link to post
Share on other sites
  • 0
limok
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 post
Share on other sites
  • 0
Slugsie

SELECT * FROM <tablename> WHERE Order NOT IN (SELECT Order FROM <tablename> WHERE Fulfilled = 'No')

 

Something along those lines should work.

  • Like 1
Link to post
Share on other sites
  • 0
limok
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 post
Share on other sites
  • 0
Slugsie

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.

  • Like 1
Link to post
Share on other sites
  • 0
IceBreakerG

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 post
Share on other sites
  • 0
limok
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 post
Share on other sites
  • 0
Slugsie

NP :)

Link to post
Share on other sites
This topic is now closed to further replies.
  • Recently Browsing   0 members

    No registered users viewing this page.