我有两个表:
shops
id | shop_name | shop_type
products
id | shop_id | product_name
我需要LEFT JOIN products ON products.shop_id = shops.id IF shop_type is 0
,我也需要JOIN products ON products.shop_id = shops.id IF shop_type is 1
。什么是最快的解决方案?代码是否很脏都没关系,性能是最重要的。
select *
from shops LEFT JOIN products ON products.shop_id = shops.id
where shop_type = 0 or (products.shop_id is not NULL and shop_type = 1)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句