Jonathan
Jonathan

Reputation: 2880

display all rows of a table after a join

I want to display all the rows of Table A after joining elements from matching column from Table B

Table A

+-----------+----------+------------+
| FirstName | LastName |    Date    |
+-----------+----------+------------+
| Tia       | Carrera  | 1975-09-18 |
| Nikki     | Taylor   | 1972-03-04 |
| Yamila    | Diaz     | 1970-03-05 |
+-----------+----------+------------+

Table B

+-----------+------------+
|    code   | Date       |
+-----------+------------+
| 1234      | 1975-09-18 |
| 56789     | 1972-03-04 |
| 54856     | 1968-07-14 |
+-----------+------------+

everything I found online looks like

+-----------+----------+------------+-----------+
| FirstName | LastName |    Date    |    code   |
+-----------+----------+------------+-----------+
| Tia       | Carrera  | 1975-09-18 | 1234      |
| Nikki     | Taylor   | 1972-03-04 | 56789     |
+-----------+----------+------------+-----------+

but this is the result that I want

+-----------+----------+------------+-----------+
| FirstName | LastName |    Date    |    code   |
+-----------+----------+------------+-----------+
| Tia       | Carrera  | 1975-09-18 | 1234      |
| Nikki     | Taylor   | 1972-03-04 | 56789     |
| Yamila    | Diaz     | 1970-03-05 |           |
+-----------+----------+------------+-----------+

Upvotes: 0

Views: 206

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269753

You want a left join:

select a.*, b.code
from a left join
     b
     on a.date = b.date;

Upvotes: 3

Related Questions