[英]Using Distinct in SQL query
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
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 ? 为了完成此查询,应如何修改上面的查询,以确保没有重复的
reco_index_content_name
行?
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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.