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 |
|
Jeremy Wadsworth
Starting Member
2 Posts |
Posted - 2006-01-31 : 11:15:40
|
| I've been looking for examples online to write a SPROC to get some data. Here are the tables.Album_CategoryAlbumCategoryID (PK, int, not null)Caption (nvarchar(max), not null)IsPublic (bit, not null)AlbumsAlbumID (PK, int, not null)AlbumCategoryID (int, null)Caption (nvarchar(max), not null)IsPublic (bit, not null)I need to return:-[Album_Category].[AlbumCategoryID]-[Album_Category].[Caption]-[Albums].[Single AlubmID for each AlbumCategoryID]-[Count of Albums in each AlbumCategory]I hope I was fairly clear in what I'm trying to do. Any tips or help would be appreciated. Thanks. |
|
|
JustinBigelow
SQL Gigolo
1157 Posts |
Posted - 2006-01-31 : 11:34:21
|
| This should work...select ac.AlbumCategoryID, ac.Caption, min(a.AlbumID), count(a.AlbumID)from Album_Category ac inner join Album a on ac.AlbumCategoryID = a.AlbumCategoryIDgroup by ac.AlbumCategoryID, ac.Caption"Hit me with a shovel 'cause I can't believe I dug you." |
 |
|
|
Jeremy Wadsworth
Starting Member
2 Posts |
Posted - 2006-01-31 : 13:02:57
|
| Thanks Justin. This worked great. I thought the SQL would be more complex than that.Thanks again. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|
|
|
|