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

  • SEARCH
  • Home
  • 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 8774995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:42:08+00:00 2026-06-13T18:42:08+00:00

Hi I have run into a dilemma, I am doing this query: SELECT GROUP_CONCAT(DISTINCT(ca.category_name)

  • 0

Hi I have run into a dilemma, I am doing this query:

SELECT GROUP_CONCAT(DISTINCT(ca.category_name) SEPARATOR ', ') AS categories, pr.promo_name, pr.add_value_text, c.contract_id, c.cmeal_plan, c.cmin_markup, c.civa, c.tax_include, c.hotel_id, hi.hname, hi.hstars, im.image_file, pl.plan_name, ra.price
FROM contracts AS c
INNER JOIN hotel_info AS hi ON hi.hotel_id = c.hotel_id AND hi.destination_id = '6460'
INNER JOIN images AS im ON im.foreign_id = hi.hotel_id
INNER JOIN meal_plan AS pl ON pl.plan_code = c.cmeal_plan AND pl.lang = '1'
INNER JOIN hotel_categories AS hc ON hc.hotel_id = hi.hotel_id
INNER JOIN categories AS ca ON ca.category_code = hc.category_code AND ca.lang = '1'
LEFT JOIN 
                    (SELECT 
                              r.hotel_id, AVG(r.double) AS price
                    FROM
                              rates AS r ) AS ra
                    ON ra.hotel_id = hi.hotel_id
LEFT JOIN promotions AS pr ON pr.hotel_id = hi.hotel_id AND FIND_IN_SET(c.contract_id, pr.contract_id) > 0 AND pr.book_start <= '2012-11-01' AND pr.book_end >= '2012-11-02' AND travel_start <= '2012-11-23' AND travel_end >=  '2012-11-30' AND pr.lang = '1'
WHERE c.cstart <= '2012-11-01' AND c.cend >= '2012-11-01'
AND hi.status = '1'
AND im.type ='1'
GROUP BY hi.hotel_id

I am getting all the desired results except for the sub select query.. each hotel has a price but it is only giving me back one result and the rest are all null. Is there an error in my query? If any additional information is needed please let me know and thank you in advance for any help!

  • 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-06-13T18:42:10+00:00Added an answer on June 13, 2026 at 6:42 pm

    You are missing the GROUP BY in your subquery, so MySQL will only return one-value. If you want all hotel_id’s then you need to GROUP BY that field:

    SELECT GROUP_CONCAT(DISTINCT(ca.category_name) SEPARATOR ', ') AS categories, 
        pr.promo_name, 
        pr.add_value_text, 
        c.contract_id, 
        c.cmeal_plan, 
        c.cmin_markup, 
        c.civa, 
        c.tax_include, 
        c.hotel_id, 
        hi.hname, 
        hi.hstars, 
        im.image_file, 
        pl.plan_name, 
        ra.price
    FROM contracts AS c
    INNER JOIN hotel_info AS hi 
        ON hi.hotel_id = c.hotel_id 
        AND hi.destination_id = '6460'
    INNER JOIN images AS im 
        ON im.foreign_id = hi.hotel_id
    INNER JOIN meal_plan AS pl 
        ON pl.plan_code = c.cmeal_plan 
        AND pl.lang = '1'
    INNER JOIN hotel_categories AS hc 
        ON hc.hotel_id = hi.hotel_id
    INNER JOIN categories AS ca 
        ON ca.category_code = hc.category_code 
        AND ca.lang = '1'
    LEFT JOIN 
    (
        SELECT r.hotel_id, AVG(r.double) AS price
        FROM rates AS r 
        GROUP BY r.hotel_id  <-- add a GROUP BY hotel_id then you will get avg() for each hotel
    ) AS ra
        ON ra.hotel_id = hi.hotel_id
    LEFT JOIN promotions AS pr 
        ON pr.hotel_id = hi.hotel_id 
        AND FIND_IN_SET(c.contract_id, pr.contract_id) > 0 
        AND pr.book_start <= '2012-11-01' 
        AND pr.book_end >= '2012-11-02' 
        AND travel_start <= '2012-11-23' 
        AND travel_end >=  '2012-11-30' 
        AND pr.lang = '1'
    WHERE c.cstart <= '2012-11-01' 
        AND c.cend >= '2012-11-01'
        AND hi.status = '1'
        AND im.type ='1'
    GROUP BY hi.hotel_id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have run into an interesting bug where it appears that when you select
I have run into this problem across multiple programming languages and I was just
I have run into this problem again and now really need to know how
I have run into a common dilemma. Many times, our company relies on using
I have run into this problem... I have two macros that look very similar
I have run into a dilemma. In a particular application, I'm receiving XML results
I have run into a wall trying to find an answer to this question
I am trying to develop a real-time feed, and have run into a dilemma.
I have run into a problem with Eclipse Indigo, attempting to start up my
I have run into a little problem. I am connecting to a webservice that

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.