Need help with SELECT syntax.

    Date: 08/23/05 (MySQL Communtiy)    Keywords: mysql, database, sql

    Okay, I have a dilemma.

    I'm not sure how to assemble a SELECT query for what I want to do.

    I have a database of ratings for books and movies. Each rating/review is placed into a new row, with a reference number for the item they're related to (actual books and movies are in their own table). and I wish to run a SELECT that will find rating entries for books that have a minimum of 5 entries (ie; 5 rows).

    I'm somewhat of a newcomer to mysql, but I'm not a complete moron. I've been able to set up long and complex query strings, but for some reason, this is befuddling me.

    Any ideas?

    ** EDIT **

    Problem solved, thanks to '[info]'timeimp & '[info]'bobalien

    The resulting query ended up being:

    $query = "SELECT book_reviews.bookid AS idofbook, avg(book_reviews.rating) "
    $query .= "AS nrating, books.bookname AS nameofbook FROM book_reviews,books "
    $query .= "WHERE books.id = book_reviews.bookid GROUP BY book_reviews.bookid "
    $query .= "HAVING count(book_reviews.rating) >= 5 ORDER BY nrating DESC LIMIT 10";

    Source: http://www.livejournal.com/community/mysql/67126.html

« Can anyone figure out why... || Hi there »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home