Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3879486
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:43:55+00:00 2026-05-19T22:43:55+00:00

I have a mySQL statement that looks like below. It tries to select all

  • 0

I have a mySQL statement that looks like below. It tries to select all restaurants (1 per row), concat the cuisines for each restaurant (as there may be 1 or more cuisines per restaurant) into a column for each restaurant, and likewise for the average rating and number of ratings.

I have setup 3 test restaurants. Restaurant 1 has 2 cuisine types and 3 ratings. The problem is that the number of ratings returns double the actual value and the cuisines return as (cuisine1 3 times then cuisine2 3 times) e.g. (cuisine1, cuisine1, cuisine1, cuisine2, cuisine2, cuisine2). Do you know what could be causing this? Thanks for any help.

SELECT
  r.*,
  GROUP_CONCAT(c.cuisine SEPARATOR ', ') cuisine,
  ROUND(AVG(re.avg_rating),1) rating,
  COUNT(re.restaurant_id) num_ratings
FROM eat_eat_restaurants r
JOIN eat_eat_restaurant_cuisines_lookup rc ON (r.restaurant_id=rc.restaurant_id)
JOIN eat_eat_cuisines c ON (rc.cuisine_id=c.cuisine_id)
LEFT JOIN eat_eat_reviews re ON (r.restaurant_id=re.restaurant_id)
WHERE r.published=1
GROUP BY r.restaurant_id
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T22:43:56+00:00Added an answer on May 19, 2026 at 10:43 pm

    GROUP BY groups the results, not the tables individually.

    In your case you want

    1. The restaurant info.
    2. The cuisines.
    3. The ratings.

    Since the “cuisines” and the “ratings” are not dependent with each other, one of them need to be grouped by itself:

    SELECT
      r.*,
      GROUP_CONCAT(c.cuisine SEPARATOR ', ') cuisine,
      reg.rating,
      reg.num_ratings
    FROM eat_eat_restaurants r
        JOIN eat_eat_restaurant_cuisines_lookup rc ON r.restaurant_id=rc.restaurant_id
        JOIN eat_eat_cuisines c ON rc.cuisine_id=c.cuisine_id
        LEFT JOIN (
            SELECT re.restaurant_id,
                ROUND(AVG(re.avg_rating),1) rating,
                COUNT(re.restaurant_id) num_ratings
            FROM eat_eat_reviews re
            GROUP BY re.restaurant_id
        ) reg ON r.restaurant_id=reg.restaurant_id
    WHERE r.published=1
    GROUP BY r.restaurant_id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MySQL database that looks like this: users ( id , name
I have a table that was created using this mysql statement below. CREATE TABLE
I have an INSERT statement that looks like this: INSERT INTO officer (officer_number, name,
I have a table that looks like this: id count 1 100 2 50
I have an order by clause that looks like: ( user_id <> ? ),
I have views which look something like this: mysql> select * from p2; +---+---------+---------+
I have an array that looks just like that: array(3) { [fk_article_id]=> string(1) 4
Does anyone have any idea what is wrong with this create statement for mysql?
I have a MySQL query that returns a result with a single column of
I have a MySQL table with approximately 3000 rows per user. One of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.