Answer the question
In order to leave comments, you need to log in
How to merge into one request?
Hello, tell me who knows.
There is a query roughly speaking: SELECT `field1, `field2`, `field3` FROM `table1` WHERE `field4` = '10';
And after this query comes the fetch:
SELECT `login` FROM `users` WHERE `id` = `field2`;
SELECT `login` FROM `users` WHERE `id` = `field3`;
Is it possible to combine everything in one query?
Answer the question
In order to leave comments, you need to log in
SELECT
table1.поле1,
table1.поле2,
table1.поле3,
user1.login AS login1,
user2.login AS login
FROM `таблица1` AS table1
LEFT JOIN `users` AS user1 ON user1.id = table1.поле2
LEFT JOIN `users` AS user2 ON user2.id = table1.поле3
WHERE table1.поле4 = '10';
SELECT поле1, поле2, поле3, users_2.title as user_2_title, users_3.title as user_3_title
FROM таблица1
left join users as users_2 on users_2.id = таблица1.поле2
left join users as users_3 on users_3.id = таблица1.поле2
WHERE поле4 = '10';
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question