sql - MySQL JOIN Complexity -


i using mysql 5.5 , have 2 tables t1(id, name) , t2(id, marks), following data in table.

t1's data

id name 1  2  b 3  c 

t2's data

id marks 1  40 5  60 

and want following resultset

id name marks 1     40 2  b    0 3  c    0 

what query can write accomplish above resultset?

left join 2 tables:

select   t1.id,   t1.name,   ifnull(t2.marks, 0) marks t1  left join t2 on t1.id = t2.id; 

sql fiddle demo


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -