A
A
Albert Kazan2018-04-20 14:20:13
MySQL
Albert Kazan, 2018-04-20 14:20:13

How to select two values ​​in one of the tables in a merged select?

There are two tables tasks and workers. Entries in tasks are tasks, and entries in workers are users.
Let's say we need to get information about a task. In the table, two fields contain IDs of two users. When you receive a task record, you need to attach the information of these two users to it as well. I can only catch one of the workers, but how to build a query to capture the second record from one table.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Danil Sapegin, 2018-04-20
@Farrien

SELECT t.*, w1.id, w1.name, w2.id, w2.name FROM tasks as t LEFT JOIN workers as w1 ON (w1.id = t.worker1_id) LEFT JOIN workers as w2 ON (w2.id = t.worker2_id)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question