Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to look up for mutiple values – need to contain all?

It is a sales order info table, and users order different products.

I need to look up the users have order all three products (01,03,05)

I know I can easily user

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

where product in

to find users ordered one of the products, but I am stuck on how to look up for users ordered all three (and of course the products are more than just those three).

Help please, thank you.

>Solution :

You can try like following using count disctinct

select UserId,count(distinct productid )
from TABLENAME
where productid in('01','02','03')
group by UserId
having count(distinct productid )=3
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading