Jump to content

Help with a GROUP BY query


logged_with_bugmenot

Recommended Posts

Hello everybody

I have a table for movie names and one below it for movie comments with the movie name database having a primary key of movieidx.

I'm trying to return the movies ordered by those with the highest numbers of comments in the database.

The query I'm running is:

SELECT movMovies.moviename,movMovies.movieidx,COUNT(movData.movieidx) AS cnt FROM movMovies,movData
WHERE movMovies.movieidx=movData.movieidx
GROUP BY movMovies.movieidx
ORDER BY cnt DESC

(movMovies holds the movie names and movData holds the comments)

It works fine, however if a movie has no comments (there's a movieidx in movMovies but no records with the corresponding movieidx in movData), it doesn't get returned at all. I think it has something to do with the WHERE clause as it can't be true if there's no corresponding movData record in there, but I'm not quite sure how to proceed.

Your help would be appreciated!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.