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 |
|
ckuo@kahluadesigns.com
Yak Posting Veteran
58 Posts |
Posted - 2002-05-28 : 13:13:36
|
| Hi,I have the following dataID Status Name1 1 Microsoft1 1 Xerox1 1 McDonalds1 2 Amtrak1 2 Adobe2 7 Barnes and Noblesand so on..I would like to view this like this:ID Status Name1 1 Microsoft1 1 McDonalds1 1 Xerox1 2 Adobe1 2 AmtrakSo its grouped by ID, within all the records where the ID is 1, the StatusID's are ordered ASC or DESC and within each group of the StatusID, the Name is alphabetical. How can I do this in one sql statment? or perhaps the best way of doing this?Thanks |
|
|
M.E.
Aged Yak Warrior
539 Posts |
Posted - 2002-05-28 : 13:21:41
|
| select *from tablewhere id = 1order by status desc , name descwhere I have desc written you can change it to asc |
 |
|
|
ckuo@kahluadesigns.com
Yak Posting Veteran
58 Posts |
Posted - 2002-05-28 : 13:45:02
|
| I tried your suggestion, but I get"Order by clause may not be used in this query type". Here is the actual sql statment.SELECT Deals.*FROM Deals INNER JOIN Tenants ON Deals.TenantID = Tenants.TenantIDWHERE Deals.BuidlingID = 1ORDER BY rankID ASC, Tenants.Name DESCCan I use order by when I have a WHERE = 1?? |
 |
|
|
ValterBorges
Master Smack Fu Yak Hacker
1429 Posts |
|
|
|
|
|