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 2000 Forums
 SQL Server Development (2000)
 Problem with Distinct, Group By operators

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-04-27 : 08:55:03
Hiren writes "Hi,
I have a query which returns the results as follows:

pk_col order_id out_dtm
----------- ----------- -------------------------
1 10 2004-04-21 10:01:38.000
2 10 2004-04-19 10:01:38.000
3 9 2004-04-16 10:01:21.633


I have these rows in the temp table. Now i want to get distinct order_ids in the order in which they appear. In above example i want 2 rows first with order_id = 10 and second with order_id = 9. So when i am executing following query :
"SELECT distinct order_id FROM @temp_table"

But this query gives result as follows :

order_id
-----------
9
10

So, here Distinct clause does the ordering on the column. Which I don't required. The same result appears when I do group by on that column.

Need solution.

Thanks,
Hiren"

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2004-04-27 : 09:30:07
GROUP BY DESC

MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page
   

- Advertisement -