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.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2004-12-07 : 08:37:21
|
| juno writes "Hi,I need to fetch the top1 record from each group.for example if i have a table like Item1 Group1 1 SubGroup1Item1 Group1 10 SubGroup10Item1 Group1 23 SubGroup23Item1 Group1 55 SubGroup55Item3 Group3 10 SubGroup10Item3 Group3 12 SubGroup12Item4 Group4 10 SubGroup10Item4 Group6 40 SubGroup50Item5 Group5 47 SubGroup47I want to fetch only Item1 Group1 1 SubGroup1Item3 Group3 10 SubGroup10Item4 Group4 10 SubGroup10Item5 Group5 47 SubGroup47i need the solution in a single sql query.kindly help.thanks" |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2004-12-07 : 09:03:59
|
ahhh...... another candidate for top 10...select * fromMyTable t1 inner join (select Item, min(id) as id from MyTable group by Item) t2 on t1.Item = t2.Item and t1.id = t2.idGo with the flow & have fun! Else fight the flow |
 |
|
|
|
|
|