基于列值的联接类型

Mindaugas Jakubauskas

我有两个表:

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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章