gpt4 book ai didi

mysql - 保持从 mysql 返回的记录唯一

转载 作者:行者123 更新时间:2023-11-29 09:02:59 26 4
gpt4 key购买 nike

有没有一种快速方法可以确保从 MySQL JOIN 查询返回的记录是唯一的?

下面的代码可能会两次返回同一类别。它的类别 ID 应该是不同的!

SELECT 
exp_categories.cat_name, exp_categories.cat_id, exp_categories.cat_url_title
,exp_category_posts.entry_id, exp_channel_titles.status
FROM (exp_categories
LEFT JOIN exp_category_posts
ON exp_categories.cat_id = exp_category_posts.cat_id)
LEFT JOIN exp_channel_titles
ON exp_category_posts.entry_id = exp_channel_titles.entry_id
WHERE exp_categories.group_id = 2
AND exp_category_posts.entry_id IS NOT NULL
AND exp_channel_titles.status = 'open'
ORDER BY RAND()
LIMIT 2

最佳答案

如果我明白您的需要,您可以通过以下方式结束您的查询:

GROUP BY exp_categories.cat_id
ORDER BY RAND()
LIMIT 2

关于mysql - 保持从 mysql 返回的记录唯一,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8020983/

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