在sql服务器中查找唯一的行值 [英] find unique row value in sql sever

查看:73
本文介绍了在sql服务器中查找唯一的行值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了用于从两个表中获取唯一值的代码....但输出不正确..... pl''z可以任何人建议我查询获取唯一记录



qyery: -



I wrote the code for fetching the unique value from tow tables....but output in not coming correct.....pl''z can any one suggest me query fro fetching unique records

qyery :-

with CTE as
(
select CouponsStock.CouponsID, ProdSubCatItemsDescription.Items_Desc_ShortDescription,
ROW_NUMBER() over(PARTITION BY CouponsStock.CouponsID, ProdSubCatItemsDescription.Items_Desc_ShortDescription order by ProdSubCatItemsDescription.Items_Desc_ShortDescription )as Cnt
from category inner join ProductCategory on
category.Cat_ID=ProductCategory.Cat_ID
inner join ProductSubCategory on ProductCategory.Prod_Cat_ID=ProductSubCategory.Prod_Cat_ID
inner join ProductSubCatItmes on ProductSubCategory.Prod_Sub_Cat_ID=ProductSubCatItmes.Prod_Sub_Cat_ID
inner join ProdSubCatItemsDescription on ProductSubCatItmes.Prod_Sub_Cat_Items_ID=ProdSubCatItemsDescription.Prod_Sub_Cat_Items_ID
inner join CouponsStock on ProdSubCatItemsDescription.Prod_Sub_Cat_Items_Desc_ID=CouponsStock.Prod_Sub_Cat_Items_Desc_ID
where category.Cat_Name='Fashion'
and ProdSubCatItemsDescription.Items_Desc_Status<>'Disabled'
and CouponsStock.CouponsEndDate>=GETDATE()
and CouponsStock.CouponsStatus='Visible'
)
select CouponsID, Items_Desc_ShortDescription
from CTE where Cnt=1







输出: -




out put :-

16	KRIAA - Men''s Handloom Embroidery Short Kurti ( TTMK 4011 )
17	KRIAA - Men''s Handloom Embroidery Short Kurti ( TTMK 4011 )
39	Crosscreek Fil-A-Fil Casual Shirt
46	Live Life Colorful : Western Wear.....
47	50% Off For Select Time Period









输出





In the output "

KRIAA - Men''s Handloom Embroidery Short Kurti ( TTMK 4011 )

重复两次.........我想只选择一次这个标题。

" repeated two times.........i want to select only one times this title.

推荐答案

这是您数据中固有的问题:该项目在数据库中存在两次,其中 CouponsID s 16 17 。你必须清理数据库!
That''s a problem inherent in your data: that item exists twice in the database, with the CouponsIDs 16 and 17. You have to clean up the database!


这篇关于在sql服务器中查找唯一的行值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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