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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:00:00+00:00 2026-05-30T05:00:00+00:00

Somehow am not successful with creating the query that I want. DB is to

  • 0

Somehow am not successful with creating the query that I want.

DB is to do with locations, there are the following tables which are relevant

  • t_location – list of locations incl. field t_location_zipcode, and t_location_id_location
  • t_zipcodecity – join table just t_zipcodecity_zipcode t_zipcodecity_id_city
  • t_city – city list with t_city_id_city
  • t_citystate – join table, t_citystate_id_city, t_citystate_id_state
  • t_state – list of states with t_state_id_state

Initially I tried to get a list of states with locations using this query:

SELECT DISTINCT `t_state_id_state`
      , `t_state_name_full` 
  FROM (`t_state`) 
LEFT JOIN `t_citystate` ON `t_state_id_state` = `t_citystate_id_state` 
LEFT JOIN `t_city` ON `t_citystate_id_state` = `t_city_id_city` 
LEFT JOIN `t_zipcodecity` ON `t_city_id_city` = `t_zipcodecity_id_city` 
LEFT JOIN `t_location` ON `t_zipcodecity_zipcode` = `t_location_zipcode` 
ORDER BY `t_state_name_full` asc ­

which works fine.

Now what I also need / want which I am failing dismally at is to get the number of locations in each state. I don’t know if it can be done in this one query or if i need another, either way I need 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-05-30T05:00:02+00:00Added an answer on May 30, 2026 at 5:00 am
    SELECT  t_state_id_state
          , t_state_name_full 
          , COUNT(DISTINCT t_location_id_location) AS locations_number
    
      FROM 
            t_state
        LEFT JOIN 
            t_citystate   ON t_state_id_state = t_citystate_id_state 
        LEFT JOIN 
            t_city   ON t_citystate_id_state = t_city_id_city 
        LEFT JOIN 
            t_zipcodecity   ON t_city_id_city = t_zipcodecity_id_city 
        LEFT JOIN 
            t_location   ON t_zipcodecity_zipcode = t_location_zipcode 
    
      GROUP BY t_state_id_state 
    
      ORDER BY t_state_name_full ASC ­
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to somehow mark Types I do not control as Obsolete?
Somehow the linebreaks are not working as they should. This is what I get:
This somehow simple task is not so simple. I can get the number of
This question somehow addresses the problem, but not from the side I'm looking for.
I've got a problem in my database - somehow changes sometimes are not being
I've somehow broken my ruby configuration, and I'm not sure how to fix it.
I have a Customer class which has all the account info.(it does NOT extend
There is one div which changes frequently it's innerHTML by ajax. Once the page
I'm creating the database for monitoring status of applications' functionalities. The logic is following:
I receive the following error when linking Chromium project: Linking... LINK.EXE.SUPALINK_ORIG : ..\build\Debug\chrome.dll not

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.