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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Get an Order By without Group By

Author  Topic 

mattt
Posting Yak Master

194 Posts

Posted - 2011-04-04 : 07:07:25
Hi,

I've got a query where I need to order the results by a column that isn't in the group by selection of the query. However, if I include it in the group by I get duplicate results that I don't want.

I seem to recall there's a new command in sql 2008 to help work around this problem, but I can't remember what it is. Can anyone point me in the right direction?

Cheers,
Matt

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2011-04-04 : 07:13:52
Post the query please. Some table defs and sample data would help too.

--
Gail Shaw
SQL Server MVP
Go to Top of Page

lionofdezert
Aged Yak Warrior

885 Posts

Posted - 2011-04-04 : 11:48:04
Try to achive your goal by using subquery or OVER clause
http://connectsql.blogspot.com/2011/03/sql-server-magical-over-clause.html?utm_source=BP_recent

--------------------------
http://connectsql.blogspot.com/
Go to Top of Page
   

- Advertisement -