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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:32:39+00:00 2026-05-11T01:32:39+00:00

So firstly here’s my query: ( NOTE:I know SELECT * is bad practice I

  • 0

So firstly here’s my query: (NOTE:I know SELECT * is bad practice I just switched it in to make the query more readable)

SELECT pcln_cities.*,COUNT(pcln_hotels.cityid) AS hotelcount   FROM pcln_cities   LEFT OUTER JOIN pcln_hotels ON pcln_hotels.cityid=pcln_cities.cityid   WHERE pcln_cities.state_name='California' GROUP BY pcln_cities.cityid   ORDER BY hotelcount DESC   LIMIT 5 

So I know that to solve things like that you add EXPLAIN to the beginning of the query but I’m not 100% sure how to read the results, so here they are:

alt text http://www.andrew-g-johnson.com/query-results.JPG

Bonus points to an answer that tells me what to look for in the EXPLAIN results

EDIT The cities tables has the following indexes (or is it indices?)

  • cityid
  • state_name
  • and I just added one with both as I thought it might help (it didn’t)

The hotels tables has the following indexes (or is it indices?)

  • cityid
  • 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. 2026-05-11T01:32:40+00:00Added an answer on May 11, 2026 at 1:32 am

    Hmm, there’s something not very right in your query. You use an aggregate function (count), but you simply group by on id. Normally, you should group on all columns in your select list, that are not an aggregate function.

    As you’ve specified the query now, IMHO, the DBMS can never correctly determine which values he should display for those columns that are not an aggregate …

    It would be more correct if your query was written like:

    select cityname, count(*) from city inner join hotel on hotel.city_id = city_id group by cityname order by count(*) desc 

    If you do not have an index on the cityName, and you filter on cityname, it will improve performance if you put an index on that column.

    In short: adding an index on columns that you regularly use for filtering or for sorting, may improve performance. (That is simply put offcourse, you can use it as a ‘guideline’, but every situation is different. Sometimes it can be helpfull to add an index which spans multiple columns. Also, remember that if you update or insert a record, indexes need to be updated as well, so there’s a slight performance cost in adding/updating/deleting records)

    Another thing that could improve performance, is using an inner join instead of an outer join. I don’t think that it is necessary to use an outer join here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 118k
  • Answers 118k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You want to add an Exit Sub to your routine:… May 11, 2026 at 11:30 pm
  • Editorial Team
    Editorial Team added an answer Oops, found the solution. If you have access to glib,… May 11, 2026 at 11:30 pm
  • Editorial Team
    Editorial Team added an answer You can try the specification pattern for this. It's a… May 11, 2026 at 11:30 pm

Related Questions

So firstly here's my query: ( NOTE:I know SELECT * is bad practice I
I have created some rounded navigation tabs using CSS and am having trouble when
Given a table of models 'A', that can have multiple child models 'B', of
Firstly, I'm in C# here so that's the flavor of RegEx I'm dealing with.
Firstly, thanks for your help. Here's my situation: I'm trying to edit the code

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.