Query to Show Certain String (1 Viewer)

Ksabai

Registered User.
Local time
Yesterday, 23:38
Joined
Jul 31, 2017
Messages
104
I Have a tbl for courier having Order Number and Reference. I have "Tea" and "Coffee" in references. I want to Show Records for "Tea" Only but Not for Order Numbers with Both "Tea" and "Coffee". Can Someone Help.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 23:38
Joined
Oct 29, 2018
Messages
21,473
Hi. Can you post some sample data, so we may be able to formulate a query to satisfy your request? Thanks.
 

Ksabai

Registered User.
Local time
Yesterday, 23:38
Joined
Jul 31, 2017
Messages
104
i have attached the screenshot of the Table
 

Attachments

  • Screenshot (9).png
    Screenshot (9).png
    8.7 KB · Views: 61

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 14:38
Joined
May 7, 2009
Messages
19,243
Code:
SELECT tbl.[OrderID], tbl.[Reference] 
FROM tblCourier 
Where 
(SELECT Count(*) From tbl AS T1 WHERE T1.[OrderID]=tbl.[OrderID])=1 
And tblCourier.[Reference]="Coffee"
 
Last edited:

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 23:38
Joined
Oct 29, 2018
Messages
21,473
I want to Show 02-Order-19.
Hi. Thanks. That would mean you want to show "coffee." If so, you could try the following query (based on your sample data of only three rows in it).
Code:
SELECT OrderID
FROM tblCourier
WHERE OrderID Not In(SELECT OrderID
FROM tblCourier
WHERE Reference="tea")
Hope it helps...
 

Ksabai

Registered User.
Local time
Yesterday, 23:38
Joined
Jul 31, 2017
Messages
104
Looks like there are some null values in the SQL it returns nothing. is there any other way to solve this
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 14:38
Joined
May 7, 2009
Messages
19,243
on which field do you have Null? if on orderID:
Code:
SELECT tbl.[OrderID], tbl.[Reference] 
FROM tblCourier 
Where 
(SELECT Count(*) From tbl AS T1 WHERE T1.[OrderID]=tbl.[OrderID])=1 
And tblCourier.[Reference]="Coffee" And IsNull(OrderID)=False;
 

Users who are viewing this thread

Top Bottom