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
 Transact-SQL (2000)
 Retrieving records after a Group By?

Author  Topic 

FruitBatInShades
Yak Posting Veteran

51 Posts

Posted - 2006-11-29 : 05:05:22
I'm a bit stuck with what I'm sure is a simple problem. I am using group by to pull a series of records from a table but because ORDER BY needs to have all the fields listed I want to use the result of the query below to then pull the full rows out of the database in the same order. Any Ideas?

SELECT     ParentType, ListType, UniqueID
FROM ListTypes
WHERE (ListType = 24)
GROUP BY ListType, ParentType, UniqueID
ORDER BY ListType, ParentType


24 24 25
24 24 28
25 24 26
25 24 27
28 24 29
28 24 30

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-11-29 : 05:08:55
The query above does not make sense. How about you provide us the full article?
What is the purpose? What are you trying to achieve?

Post some sample data, your expected output based on the provided sample data and some table DDL.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-11-29 : 05:09:27
The way you are using GROUP BY right now, you can also use DISTINCT keyword.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2006-11-29 : 10:22:44
GROUP BY is generally used to prodoce some AGGREGATE information....ie SUM or AVG, MIN, MAX, etc....you are doing none of these....and thus missing the point of the GROUP BY clause.

However...to achieve your target you could do something along the lines of....

select * from (
SELECT ParentType, ListType, UniqueID
FROM ListTypes
WHERE (ListType = 24)
GROUP BY ListType, ParentType, UniqueID) taba
order by 1,3,2
Go to Top of Page
   

- Advertisement -