是否有一种快速方法来确保您从MySQL JOIN查询返回的记录是唯一的?从mysql中保存返回的记录是唯一的
下面的代码可能会带回两次相同的类别。它的类别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