Mohammad Raha Mohammad Raha - 2 months ago 6
MySQL Question

join to tables on a condition and return that data that against with condition

I have two table(

table1
,
table2
). now i wanna to read all form
table1
if
field1
equal to
table2
.
filed2
and if not equal.

I hope understand my problem.

I need to read all of
table1
data and read
table2
filed if have relation or key in
table1
.

how i can get all of data just with a query.

Answer

Use a LEFT JOIN. LEFT join will bring you all the result from the table which is in the left side of the JOIN clause and matching records from the Table which is in the right side of the JOIN based on the matching criteria mentioned in the ON condition . If there is no match query will return you NULL values for the selected columns of the table in the right side of the JOIN condition.

 SELECT *
 FROM table1 t1
   LEFT  JOIN table2 t2
        ON t1.Field1=t2.Field2