Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to pass dynamic string in my query ???
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Constraint Violating Yak Guru

252 Posts

Posted - 01/31/2013 :  03:05:33  Show Profile  Reply with Quote
Hello all ,

Here i am facing some issue i'm not getting any push to move on or this one exists

i am joining data from Three tables A,B and C

A.ID B.Name C.Description
1 ram good
2 mohan Average
3 charan good
4 rohan Average
5 tareni good
6 chinta Average

here in my query i am using distinct top 2 ID so that i am getting

2 results now i just want to get distinct description top2 with out id is that possible ??

select distinct top 2 A.ID B.Name C.Description from table

i need to get only distinct C.Description rest of the should neeed to be there but main one is C.Description


Very Important crosS Applying yaK Herder

52326 Posts

Posted - 01/31/2013 :  04:14:42  Show Profile  Reply with Quote

SELECT your columns....
(SELECT your current columns...,DENSE_RANK() OVER (ORDER BY descriptionField) AS Seq
... your existing query

WHERE Seq<=2

SQL Server MVP

Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000