本文介绍了在 SQL 查询中使用 Distinct的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请找到下面给出的查询:
Please find the query given below:
SELECT DISTINCT reco_index_content_code, reco_index_content_name, reco_index_content_url FROM tbl_reco_index_contents WHERE reco_index_user_action_at_select = 1 AND user_profile_number = 1我需要选择 reco_index_content_name 作为不同的.
I need to select reco_index_content_name as distinct.
应该如何修改上面的查询,以实现这一点,使得没有重复的 reco_index_content_name 行?
How should the above query be modified, in order to accomplish that, such that there are no duplicate reco_index_content_name rows ?
推荐答案标准解决方案已记录并使用如下不相关的子查询:
The standard solution is documented and uses an uncorrelated subquery as follows:
SELECT x.* FROM my_table x JOIN ( SELECT grouping_id , MIN(ordering_id) min_ordering_id FROM my_table GROUP BY grouping_id ) y ON y.grouping_id = x.grouping_id AND y.min_ordering_id = x.ordering_id;更多推荐
在 SQL 查询中使用 Distinct
发布评论