Mysql – Which join to use

join;MySQL

I have two tables with one primary key present on both of them lets call them LEFT table and RIGHT table.I want to make a join such that I get all the rows of left table only ,i.e. if ROW from RIGHT table matches the JOIN condition it should get horizontally appended to the specific row.Else all NA in second half of the row,so that number of rows in the join can only by equal to number of rows in LEFT table

Best Answer

You are describing a LEFT JOIN. e.g.

select table1.column1 as "left", table2.column2 as "right"
from table1 
left join table2 on table1.column1 = table2.column2;

This will list all values in table1.column1 on the left, and any values in table2.column2 that match on the right. If they don't match, the field in the right column will be null.