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 - 2002-06-25 : 08:23:44
|
| Bret Bonnell writes "Hi,I am trying to return a set of records grouped by the usergroupid field. What I want to do is to return one recordset with the the 4's at the beginning of the recordset, the 9's next, and the 7's last. The query below will return one recordset, but it doesn't group them correctly. It simply orders the entire recordset by the usergroupid field. Any help would be greatly appreciated.Thanks!SELECT id, firstname, lastname, usergroupid FROM users WHERE usergroupid = 4UNIONSELECT id, firstname, lastname, usergroupid FROM users WHERE usergroupid = 9UNIONSELECT id, firstname, lastname, usergroupid FROM users WHERE usergroupid = 7ORDER BY usergroupid" |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2002-06-25 : 08:32:25
|
| order by case usergroupid when 4 then 1when 9 then 2when 7 then 3end==========================================Cursors are useful if you don't know sql.Beer is not cold and it isn't fizzy. |
 |
|
|
mzanaty
Starting Member
8 Posts |
Posted - 2002-06-27 : 21:37:00
|
| I often use a generic subgrouping template:select 1 as ordr, ...unionselect 2 as ordr, ......order by ordr |
 |
|
|
|
|
|
|
|