mysql - SQL optional parameter? -
lets have 2 tables:
table1
id name 1 joe 2 greg 3 susan 4 max table2
uid comment 2 customer 4 great guy what want list elements of table 1, , if table1.id = table2.uid want select comment. if comment not exist give blank field.
result should be:
1 joe 2 greg customer 3 susan 4 max great guy i can't figure out how it, if write:
select table1.id, table1.name, table2.comment table1.id=table2.uid it gives me users 2 , 4.
try use left join shows data table1
select t1.id, t1.name, t2.comment table1 t1 left join table2 t2 on t1.id=t2.uid note:
good practice use aliases above. code more readable.
Comments
Post a Comment