一個主表,一個附表,一箇中間表ci
表結構 主表中有mobile,中間表有mobile,id,附表中有id(is_defalut=1,保證只有一條)it
條件保證主表必定顯示,附表、中間表均可覺得空mobile
select a.*,d.* from a left join (select c.*,b.mobile from b,c where b.id=c.id and c.is_default=1) d on a.mobile=d.mobileselect
實例:di
select a.*,d.consignee shname,d.mobile shmobile,d.province shprovince,d.city shcity,d.district shdistrict,d.address shaddress FROM tp_signup a LEFT JOIN (select c.consignee consignee,c.province province,c.city city,c.district district,c.address address,b.mobile mobile FROM tp_users b,tp_user_address c where b.user_id=c.user_id and c.is_default=1) d ON a.mobile=d.mobilevi