D
D
depressionofoleg2021-06-28 10:57:20
MySQL
depressionofoleg, 2021-06-28 10:57:20

How to specify WHERE correctly if we do LEFT JOIN?

I recently started learning MySQL, so don't be too harsh.
There are 3 databases, one with names and IDs (users), the second one for joining multiple selections (group_type), the third c with types and IDs (types). How to create a correct RIGHT JOIN between tables to indicate that the table will WHERE on id user (that is, select a separate user).
Code example:

SELECT u.*, t.type_name, t.description FROM users AS u WHERE id = 1
                LEFT JOIN type_user AS tu ON tu.id_user = u.id 
                LEFT JOIN types AS t ON tu.id_type = t.id AND;

If you specify WHERE at the beginning, it gives an error, and the table is needed only for a user with a certain id.
Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Akina, 2021-06-28
@depressionofoleg

The order of the slander in the query is clearly defined in the documentation , and does not imply any changes or permutations (the exception is the INTO slander when placing the result in a variable for which 3 different locations are described).

SELECT u.*, t.type_name, t.description 
FROM users AS u 
LEFT JOIN type_user AS tu ON tu.id_user = u.id 
LEFT JOIN types AS t ON tu.id_type = t.id
WHERE u.id = 1;

S
shellnet, 2021-06-28
@warlinx

where after all joins indicate

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question