Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Order By, Group By 1

Status
Not open for further replies.

goodmanrAy

Programmer
Feb 6, 2002
53
0
0
GB
Hi

Is it possible to Group together fields then order by a different field.
e.g.
I have 2 columns
ID1 - ID2

A - 3
A - 4
A - 5
B - 1
B - 6
C - 2
C - 7

I want to group by ID1 but order by ID2
i.e I want out

B - 1
B - 6
C - 2
C - 7
A - 3
A - 4
A - 5

in that particular order

thanks

Andrew
 
Will this work?
Code:
select A.* 
from blah A
inner join 
(	select ID1, min(ID2) as minid
	from blah
	group by ID1
) B
on A.ID1=B.ID1
order by B.minid, A.ID2

------
"There's a man... He's bald and wears a short-sleeved shirt, and somehow he's very important to me. I think his name is Homer."
(Jack O'Neill, Stargate)
[banghead]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top