php - How to join two tables without duplicates? -
i have in table looks this:
id_in | date_in -------|-------------------------- 1 | 2016-04-29 02:00:00
and out table looks this:
id_out | date_out ----------|-------------------------- 1 | 2016-04-29 03:00:00 2 | 2016-04-29 04:00:00 3 | 2016-04-29 05:00:00
i want write query output looks this:
id_in | date_in | id_out | date_out ------|---------------------------- |----------------------------|--------------------------- 1 | 2016-04-29 02:00:00 | 1 |2016-04-29 03:00:00 null | null | 2 |2016-04-29 04:00:00 null | null | 3 |2016-04-29 05:00:00
you can left join
:
select i.id_in, i.date_in, o.id_out, o.date_out outtable o left join intable on o.id_in = i.id_out;
Comments
Post a Comment