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

Get a row based on data from another table

I have the following tables:

dialogs:
id

and

users_dialogs:
user_id
dialog_id

How can I get (SELECT FROM …) a dialog ID by two user IDs? Example:

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

dialogs:
id: 1
users_dialogs:
user_id: 2 | dialog_id: 1
user_id: 7 | dialog_id: 1

need return dialog with id = 1… idk how

>Solution :

This query gets the user_ids and the dialog_ids from users_dialogs where the dialog_id exists in the dialogs table.

SELECT user_id, dialog_id FROM users_dialogs WHERE user_id IN (2,7)

Gives

users_dialogs:
user_id: 2 | dialog_id: 1
user_id: 7 | dialog_id: 1

You need to fill the user_ids programmatically in your code

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