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

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

mohan123
Constraint Violating Yak Guru

India
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

P.V.P.MOhan

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

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

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

)t
WHERE Seq<=2


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

Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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