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 |
|
NewMedia42
Starting Member
35 Posts |
Posted - 2004-10-06 : 22:35:38
|
| I'm trying to find the simpliest method to do the following. I currently can do it using cursors, but I'd like to know if there are any other alternatives that might lend themselves to clearer/faster performance.I have two tables:TableItem contains:(int) ItemID(int) CategoryID(varchar) NameTableCategory(int) CategoryID(varchar) NameWhat I want to return is the members of TableItem sorted by name, grouped by CategoryID which is also sorted by name. If I wasn't interested in sorting by the Category name, then I could easily use:select * from [TableItem] order by [CategoryID],[Name]but this ignores the Name of the Category, instead basically listing in the order they were inserted in the DB. My cursor implementation is pretty basic as well, I go through TableCategory, then do the above query minus the [CategoryID] filter and adding a WHERE ID=CursorID.Hopefully that's clear enough to everyone - any help would be greatly appreciated! |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2004-10-06 : 23:07:20
|
| are you familiar with JOIN's ?- Jeff |
 |
|
|
derrickleggett
Pointy Haired Yak DBA
4184 Posts |
Posted - 2004-10-06 : 23:35:32
|
| SELECTti.ItemID,ti.CategoryID,ti.NameFROMTableItem tiINNER JOIN TableCategory tc ON ti.CategoryID = tc.CategoryIDORDER BYti.CategoryID,ti.Name--Is this what you are looking for?--Bad day Jeff? lolMeanOldDBAderrickleggett@hotmail.comWhen life gives you a lemon, fire the DBA. |
 |
|
|
|
|
|