gpt4 book ai didi

mysql - 联合查询后选择唯一的行

转载 作者:行者123 更新时间:2023-11-29 22:40:20 26 4
gpt4 key购买 nike

有这个查询:

(select status, cb_ebook, product_id, titel, auther, image from oc_product where status and cb_ebook and titel like '%term%') 
UNION
(select status, cb_ebook, product_id, titel, auther, image from oc_product where status and cb_ebook and auther like '%term%')

但是,结果中有重复的行,我只想要唯一的product_id - 我尝试按product_id分组,但这不起作用。

有什么解决办法吗?

最佳答案

您可以尝试在联合查询后添加不同的值,例如这样?

SELECT distinct(x.status) status,x.cb_ebook,x.product_id,x.titel,x.auther,x.image
FROM
(
(select status, cb_ebook, product_id, titel, auther, image from oc_product where status and cb_ebook and titel like '%term%')
UNION
(select status, cb_ebook, product_id, titel, auther, image from oc_product where status and cb_ebook and auther like '%term%')
) x

关于mysql - 联合查询后选择唯一的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29395231/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com