How do I get the IDs of everybody with specific rows/values in MySQL

Matt

I have a table that consists of the following:

|---------------------|------------------|
|     CustomerID      |     Product ID   |
|---------------------|------------------|
|          1          |         101      |
|---------------------|------------------|
|          1          |         102      |
|---------------------|------------------|
|          1          |         103      |
|---------------------|------------------|
|          2          |         101      |
|---------------------|------------------|
|          2          |         105      |
|---------------------|------------------|

I only want to select unique Customer IDs where they have exactly the product IDs of 101, 102, 103. I don't want to pull in customer with ID 2 because, although they have Product ID 101, they don't have the correct combination.

isaace

This should work:

SELECT CustomerID 
FROM myTables
WHERE ProductID IN(101,102,103)
GROUP BY CustomerID
HAVING COUNT(DISTINCT ProductID) = 3

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I deny access to everybody but me in Windows 7?

From Dev

How do I get specific data from a specific column in MySQL?

From Dev

How do I get sequential thread ids

From Dev

What bunch of ffmpeg scripts do I need to get HTML5-compatible "Video for everybody"?

From Dev

How to get records with specific IDs?

From Dev

How do i get IDs from multiple rows without using AND

From Dev

how do I get the pid of a specific process

From Dev

How do I get notifications for specific folders?

From Dev

How do I match ids?

From Dev

In Coredata, how to get all IDs for specific table?

From Dev

Why do I get shared Ids with JPA?

From Dev

How to get rows with array of ids in MySQL

From Dev

MySQL can I insert specific ids into an auto-increment column

From Dev

In MySQL How do I SELECT all ids from rows with a similar value

From Dev

How do I assign auto-incrementing IDs that restart for each new person in MySQL?

From Dev

How do I write a MySQL query to group results while preserving IDs of particular rows?

From Dev

In MySQL How do I SELECT all ids from rows with a similar value

From Dev

MySQL: How do a i insert a specific number of blank rows into a table

From Dev

MySQL: How do a i insert a specific number of blank rows into a table

From Dev

How do I find a table in MySQL with 2 specific columns in it

From Dev

How can I get the attributes from a mysql table by specific column?

From Dev

How do I find ids in an xml file?

From Dev

How do I get a list of authors and committer IDs in a Git pre-commit hook?

From Dev

Using Google Analytics web components, how do I get all of the property IDs?

From Dev

How do I get specific information out of Mediainfo

From Dev

How do I get the image data on specific objects?

From Java

How do I get the key at a specific index from a Dictionary in Swift?

From Java

How do I import a specific version of a package using go get?

From Dev

How do I get users with a specific email domain from PostgreSQL?

Related Related

  1. 1

    How do I deny access to everybody but me in Windows 7?

  2. 2

    How do I get specific data from a specific column in MySQL?

  3. 3

    How do I get sequential thread ids

  4. 4

    What bunch of ffmpeg scripts do I need to get HTML5-compatible "Video for everybody"?

  5. 5

    How to get records with specific IDs?

  6. 6

    How do i get IDs from multiple rows without using AND

  7. 7

    how do I get the pid of a specific process

  8. 8

    How do I get notifications for specific folders?

  9. 9

    How do I match ids?

  10. 10

    In Coredata, how to get all IDs for specific table?

  11. 11

    Why do I get shared Ids with JPA?

  12. 12

    How to get rows with array of ids in MySQL

  13. 13

    MySQL can I insert specific ids into an auto-increment column

  14. 14

    In MySQL How do I SELECT all ids from rows with a similar value

  15. 15

    How do I assign auto-incrementing IDs that restart for each new person in MySQL?

  16. 16

    How do I write a MySQL query to group results while preserving IDs of particular rows?

  17. 17

    In MySQL How do I SELECT all ids from rows with a similar value

  18. 18

    MySQL: How do a i insert a specific number of blank rows into a table

  19. 19

    MySQL: How do a i insert a specific number of blank rows into a table

  20. 20

    How do I find a table in MySQL with 2 specific columns in it

  21. 21

    How can I get the attributes from a mysql table by specific column?

  22. 22

    How do I find ids in an xml file?

  23. 23

    How do I get a list of authors and committer IDs in a Git pre-commit hook?

  24. 24

    Using Google Analytics web components, how do I get all of the property IDs?

  25. 25

    How do I get specific information out of Mediainfo

  26. 26

    How do I get the image data on specific objects?

  27. 27

    How do I get the key at a specific index from a Dictionary in Swift?

  28. 28

    How do I import a specific version of a package using go get?

  29. 29

    How do I get users with a specific email domain from PostgreSQL?

HotTag

Archive