mysql - Search data from two table with joins how to handler null values -
i have write search query joining 2 different table. have putted left join on both. first table contains 60records while based on second table has 30. wanted if search query should return 60records. right returning 30. query same.
select a.,b. left join b on a.id=b.aid a.name=ifnull('tst',a.name) , b.class=ifnull('c',b.class).
please guide me, thanks.
it's wise remember join operations (all kinds of join operations, left, right, inner, outer) have purpose of creating new, virtual, table assembled tables joined together.
what joined virtual table supposed have in it? in case, meaning of column a.id, , column b.aid?
- are there rows in table a.id column values occur no times in b.aid?
- are there rows in b table b.aid column values occur no times in a.id?
if answer question 1 yes , question 2 no, left join give want want. simplify query. try this.
select a.*, b.* left join b on a.id = b.aid if happen want rows there no corresponding row b, try this.
select a.* left join b on a.id = b.aid b.aid null if answer both questions yes, may want this:
select a.*, b.* outer join b on a.id = b.aid but should think through carefully.
Comments
Post a Comment