Q: join statement using if else in mysql Let me get straight to the problem.Here's my sql fiddle sql fiddle
Now my requirement is to retrieve name column from either table B or table C by using join statement with table A under following condition
If result is present in table B retrieve name from table B and ignore table C
else retrieve name field from table c

Basically i require following result
1 AB name1
2 BC name2
3 CD name3


A: select id,A.column1,D.name from A left join 
(select * from B union select * from C) as D on A.column1=D.column1


A: select * from B
UNION 
select * from C where column1 not in (select column1 from B)
order by name

SQL Fiddle link: http://sqlfiddle.com/#!2/5f4f4/16

A: You don't need to do if statement as you mentioned. Just try the following:
 select A.id, A.column1 from A left join B on A.column1 = B.column1 
 left join C on C.column1 = A.column1;

SQL Fiddle
