mysql根据字段值关联查不同表:
实现:
使用left join 结合case when 判断直接取值:
select mp.member_id ,mp.store_id, case mp.store_type when 1 then bs.store_namewhen 2 then sc.store_namewhen 3 then be.store_name end as 'store_name'from mc_profiles mp left join bas_store bs on bs.id=mp.store_id left join bas_sports_city sc on sc.id=mp.store_id left join bas_extros be.id=mp.store_id