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

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to pass dynamic string in my query ???

Author  Topic 

mohan123
Constraint Violating Yak Guru

252 Posts

Posted - 2013-01-31 : 03:05:33
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

P.V.P.MOhan

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-01-31 : 04:14:42
[code]
SELECT your columns....
FROM
(SELECT your current columns...,DENSE_RANK() OVER (ORDER BY descriptionField) AS Seq
FROM...
... your existing query

)t
WHERE Seq<=2
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -