我需要使用distinct来避免重复的行,但它不应该对列进行排序 [英] I need to use distinct to avoid duplicate rows but it should not sort the column

查看:372
本文介绍了我需要使用distinct来避免重复的行,但它不应该对列进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我写了一个查询...我使用Distinct删除行上的重复项但结果已排序...我怎样才能避免这个。这是我的查询



SELECT DISTINCT ProductPackageID,packageName,name,(SELECT STUFF((SELECT','+ Details FROM @ProductPackage WHERE Name = t.NAME FOR XML路径('')),1,1,''))AS详情来自@ProductPackage t





这会产生名称列要排序..我不想那样。请帮忙。



谢谢。

Hi All,

I wrote a query ...I have used Distinct to remove duplicates on rows but the result is sorted...How can i avoid this. Here is my query

SELECT DISTINCT ProductPackageID,packageName, name,(SELECT STUFF((SELECT ',' + Details FROM @ProductPackage WHERE Name=t.NAME FOR XML PATH('')),1,1,'')) AS Details FROM @ProductPackage t


This yields the name column to be sorted..I dont want that.Please help.

Thanks.

推荐答案

你可以在自己上添加一个order by子句。如果没有order by子句,SQL将根据聚簇索引或记录的实际顺序对结果进行排序。
You can add an order by clause on yourself. If there is no order by clause SQL will order the results based on the clustered index or the actual order of the records.


这篇关于我需要使用distinct来避免重复的行,但它不应该对列进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆