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 7163249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:52:17+00:00 2026-05-28T13:52:17+00:00

I have two queries, the only difference being the GROUP BY clause SELECT *

  • 0

I have two queries, the only difference being the GROUP BY clause

SELECT * FROM `packages_sorted_YHZ` WHERE `hotel_city` = 'Montego Bay'
ORDER BY  `deal_score` DESC 
LIMIT 0,3;

SELECT * FROM `packages_sorted_YHZ` WHERE `hotel_city` = 'Montego Bay'
GROUP BY `hotel_name`
ORDER BY  `deal_score` DESC
LIMIT 0,3;

The first query returns the first result with a deal_score of 75 but the second query returns the first result with the deal_score of just 72.

I would have thought that regardless of the GROUP BY clause, the first result would have the highest deal score possible (75)

The purpose of the GROUP BY clause is to optionally select a unique hotel_name for each result.
Does anyone know what I’m doing wrong here.

  • 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-28T13:52:18+00:00Added an answer on May 28, 2026 at 1:52 pm

    Without being able to look at all the data, my best guess is that Group By is merging the data and giving you an arbitrary value that matches the Where clause. This will happen if hotel name isn’t unique, and you won’t be given the maximum score unless you specifically query for it.

    Try putting a Max() around deal_score. In MySQL, Group By can be used way too easily, I like how MSSQL enforces the use of aggregate functions and grouping by every field that isn’t aggregated. Try this query:

    SELECT `hotel_name`, MAX( `deal_score` ) AS `max_score` FROM `packages_sorted_YHZ` WHERE `hotel_city` = 'Montego Bay'
    GROUP BY `hotel_name`
    ORDER BY  `max_score` DESC
    LIMIT 0,3;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two queries, as following: SELECT SQL_CALC_FOUND_ROWS Id, Name FROM my_table WHERE Name
I have two mysql queries: $sql = SELECT * FROM content WHERE threadName LIKE
I have the following two queries: select count(*) from segmentation_cycle_recipients scr , segmentation_instance si
I have a query to select from another sub-query select. While the two queries
I have two queries to get related tags from a mysql database, one works,
I have two queries that are basically the same: OLD TRANSACTIONS QUERY SELECT t.payment_method,
I'm seeing OraclePreparedStatement executeQuery() exhibit serialization. That is, I have two queries that I
What's the difference between these two queries? I've been resistant to jumping on the
In my application I have two queries which will be quite frequently used. The
Hi I have two questions about MySQL and QUERIES. First of all i've like

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.