A
A
andreygeraskin2021-05-28 12:26:59
SQL
andreygeraskin, 2021-05-28 12:26:59

How to write a complex SQL query using multiple tables?

There is a program (chat). It has a database-bound control that should show chats that have a user. There are several tables: a table with users, a table with chats, and a link table (chat-user). That is, the query should receive the user's name, get his id in the users table, then select from the connecting table ids of chats in which the user exists by this id, and finally look into the table with chats and return these records from the chat table by the chat ids received earlier .

I myself am a complete zero in the database. I could do all this directly in the program using several queries, but I want, first of all, to simplify the code, and it looks prettier.

Can you please tell me if it is possible to implement this in one request, and if so, how?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2021-05-28
@Rsa97

JOIN or WHERE ... IN

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question