我有表 Product 和 ProductDetails。在 ProductDetails 中,我有包含多种语言的产品描述的行(按 lang 列区分)。并非每个产品都有每种语言的描述。如何进行选择以选择指定语言的描述(通过Where productDescription.lang = 'en'
),如果指定的语言不存在,则将选择默认语言的描述(默认语言的描述始终存在)。
我做的:
select *
from product
left join productDetails on product.id = productDetails.product_id
where productDetails.language = 'en';
我得到了英语的所有详细信息。如果 en 不存在,如何修改此选项以选择默认语言的详细信息?
类似的事情。我不知道你的确切架构:
select
p.id,
if(IS NULL d2.description, d1.description, d2.description ) `description`
from product p
join productDetails d1
on product.id = productDetails.product_id
and
productDetails.language = 'default_lang'
left join productDetails d2
on product.id = productDetails.product_id
and
productDetails.language = 'en'
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)