Click here to Skip to main content
15,881,089 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 :-

SQL
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.
Posted

1 solution

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!
 
Share this answer
 
Comments
Sumit_Kumar_Sinha 21-Jan-13 2:42am    
any other way to fetch Unique CouponsID and title

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900