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 |
|
helixpoint
Constraint Violating Yak Guru
291 Posts |
Posted - 2009-03-14 : 09:12:18
|
| I need to have a count of the movies in each genreI have 2 tables movies and genreI tried this, but it did not workSELECT COUNT(*) AS ItemCount, genre.genreID, genre.genreDesc, movies.IDFROM genre INNER JOIN movies ON genre.genreID = movies.genreIDGROUP BY genre.genreID, genre.genreDesc, movies.IDDaveHelixpoint Web Developmenthttp://www.helixpoint.com |
|
|
mfemenel
Professor Frink
1421 Posts |
Posted - 2009-03-14 : 09:21:37
|
| not sure about your table structure but if movies.id is unique to each movie then your count is only going to return 1 because you're grouping by a field that is distinct. If this is the case then to solve your problem, remove the movies.id from your select and your group by statement and you should end up with a count by genreIDMike"oh, that monkey is going to pay" |
 |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2009-03-14 : 14:52:45
|
| [code]SELECT COUNT(*) AS ItemCount, genre.genreID, genre.genreDescFROM genre INNER JOIN movies ON genre.genreID = movies.genreIDGROUP BY genre.genreID, genre.genreDesc[/code]CODO ERGO SUM |
 |
|
|
|
|
|