Join two mysql SELECT queries with the same id -
i have 2 select queries:
select a.id, a.prev_task s_task_assignment
and
select d.id, a.first_name, a.last_name s_users a, s_task_assignment d a.id = d.responsible_id
they have 1 same column - a.prev_task
, d.id
. columns contains id.
so need somehow join results of 2 queries a.prev_task = d.id
not know how.
you can put in one query like:
select a.id, a.prev_task, d.id, b.first_name, b.last_name s_task_assignment a, s_users b, s_task_assignment d a.prev_task = d.prev_task and b.id = d.responsible_id
so renamed a
in second query b
, , furthermore added table of first query from
clause , added a.prev_task = d.prev_task
filter.
you can make syntactically more elegant using join
statements, like:
select a.id, a.prev_task, d.id, b.first_name, b.last_name s_users b join s_task_assignment d on b.id = d.responsible_id join s_task_assignment on a.prev_task = d.prev_task
Comments
Post a Comment