Find all rows with with values from list and which all have the same id MYSQL

Matt Sich

I have a table with conversation ids which is a one-to-many relationship to another table that has conversation users. The conversation users table has the id for the conversation, a unique id and a userID. I can use this:

SELECT c_id FROM conversations INNER JOIN conversation_users on conversation_users.cu_convo_id = conversations.c_id

which gives me all the rows but I need to find a way to do something like an IN statement because I need to find the conversation id given two user IDs.

Any ideas? Am I approaching this the wrong way completely?

WORKING ANSWER: IN case anyone needs it, the following worked for me:

SELECT cu_convo_id FROM conversations 
INNER JOIN conversation_users on 
conversation_users.cu_convo_id = conversations.c_id 
WHERE cu_user_id IN (31,42) 
GROUP BY cu_convo_id
HAVING count(distinct cu_user_id) = 2;

if I have 5 IDs to find, i put them on line 4 and then put the number 5 on line 6

Fenistil

Simply add a WHERE to your SQL:

SELECT c_id FROM conversations 
INNER JOIN conversation_users on 
conversation_users.cu_convo_id = conversations.c_id 
WHERE conversations.usedID IN (1,2);

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 to get all the rows from MySQL table which have same values for multiple columns?

From Dev

mysql select all rows that have same value from id

From Dev

mysql select all rows that have same value from id

From Dev

MYSQL find all rows where second row have given values

From Dev

How to find all rows that have all values which has another row

From Dev

MYSQL update a row if all multiple rows that belong to the same foreign ID have same value

From Dev

MySQL, insert values in all rows except id

From Dev

How to select all rows which have identical values

From Dev

Iterating over all rows with the same id and find matching values in a different table

From Dev

SQL: Find all rows in a table for which all rows in another table that refer to the original row have a certain property

From Dev

In Mysql how to get records which for the same foreign key has all values showed up in a list for another col

From Dev

SQL get count of all rows that have the same id

From Dev

Deleting all same values from Generic List

From Dev

Find all rows, that have at least n values in common with a specific item

From Dev

SQL - find all the rows where the values are the same, or next biggest

From Dev

For each row, find all rows with same values in column

From Dev

MySQL: Select all that only have two rows, with specific values?

From Dev

Mysql SELECT name where all rows with the name have certain values

From Dev

get all rows from table that have both variables in a same column

From Dev

MySQL many-to-many junction table: Select all entries from A which contain no values in B not in list

From Dev

MySQL many-to-many junction table: Select all entries from A which contain no values in B not in list

From Dev

Grabbing all rows from a database that have specific column values in laravel

From Dev

Find and convert to NULL all duplicated values from the same column in a list of dataframes

From Dev

How do I create a new column that holds all the primary key values of all rows that have the same value?

From Dev

Get all the rows which are not have leading zero

From Dev

Deleting all rows from table that share the same ID

From Dev

Mysql - select rows which have linked values

From Dev

Get rows which do have references to list of values and at the same time don't have any references to list of other values

From Dev

How to make all rows have same size?

Related Related

  1. 1

    How to get all the rows from MySQL table which have same values for multiple columns?

  2. 2

    mysql select all rows that have same value from id

  3. 3

    mysql select all rows that have same value from id

  4. 4

    MYSQL find all rows where second row have given values

  5. 5

    How to find all rows that have all values which has another row

  6. 6

    MYSQL update a row if all multiple rows that belong to the same foreign ID have same value

  7. 7

    MySQL, insert values in all rows except id

  8. 8

    How to select all rows which have identical values

  9. 9

    Iterating over all rows with the same id and find matching values in a different table

  10. 10

    SQL: Find all rows in a table for which all rows in another table that refer to the original row have a certain property

  11. 11

    In Mysql how to get records which for the same foreign key has all values showed up in a list for another col

  12. 12

    SQL get count of all rows that have the same id

  13. 13

    Deleting all same values from Generic List

  14. 14

    Find all rows, that have at least n values in common with a specific item

  15. 15

    SQL - find all the rows where the values are the same, or next biggest

  16. 16

    For each row, find all rows with same values in column

  17. 17

    MySQL: Select all that only have two rows, with specific values?

  18. 18

    Mysql SELECT name where all rows with the name have certain values

  19. 19

    get all rows from table that have both variables in a same column

  20. 20

    MySQL many-to-many junction table: Select all entries from A which contain no values in B not in list

  21. 21

    MySQL many-to-many junction table: Select all entries from A which contain no values in B not in list

  22. 22

    Grabbing all rows from a database that have specific column values in laravel

  23. 23

    Find and convert to NULL all duplicated values from the same column in a list of dataframes

  24. 24

    How do I create a new column that holds all the primary key values of all rows that have the same value?

  25. 25

    Get all the rows which are not have leading zero

  26. 26

    Deleting all rows from table that share the same ID

  27. 27

    Mysql - select rows which have linked values

  28. 28

    Get rows which do have references to list of values and at the same time don't have any references to list of other values

  29. 29

    How to make all rows have same size?

HotTag

Archive