在 SQL 查询中使用 Distinct

编程入门 行业动态 更新时间:2024-10-26 08:27:27
本文介绍了在 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

本文发布于:2023-10-20 22:22:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1512312.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:SQL   Distinct

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!