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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:12:52+00:00 2026-06-12T15:12:52+00:00

The base zip code used in this query is the lat/lng for 90210 which

  • 0

The base zip code used in this query is the lat/lng for 90210 which has an average agi (for 2008) of over $400k. I don’t expect it to show up in this output because of the BETWEEN range of 100000 and 200000.

SELECT 
  zip, city, state, avg_agi, 
  ( 3959 
      * acos( 
              cos( radians(34.088808) ) 
            * cos( radians( lat ) ) 
            * cos( radians( lng ) - radians(-118.40612) ) 
            + sin( radians(34.088808) ) 
            * sin( radians( lat ) ) 
        ) 
  ) AS distance 
FROM 
  zip_codes, avgagi 
where 
      zip=zipcode 
  and avg_agi BETWEEN 100000 and 200000 
HAVING 
  distance < 5 ORDER BY distance LIMIT 0 , 10000;

+-------+----------------+-------+---------+------------------+
| zip   | city           | state | avg_agi | distance         |
+-------+----------------+-------+---------+------------------+
| 90069 | West Hollywood | CA    |  121753 | 1.42816585190112 |
| 90211 | Beverly Hills  | CA    |  164538 | 2.06804933097035 |
| 90024 | Los Angeles    | CA    |  187134 | 2.47751318825072 |
| 90025 | Los Angeles    | CA    |  130983 | 3.76591348160737 |
| 91604 | Studio City    | CA    |  103328 |  3.8634176735557 |
| 90064 | Los Angeles    | CA    |  130769 | 3.95933331921038 |
| 90068 | Los Angeles    | CA    |  100370 | 4.52908379278674 |
+-------+----------------+-------+---------+------------------+

However, for my application I need it to include the base zip code in the output. It was suggested I use a WHERE with OR for zip=”90210″, however I’m having a very difficult time figuring out how to make that work. When I try to incorporate that suggestion it spins for the longest time and never comes back.

How can I modify the above MySQL query to have it include the zip code of 90210, regardless of the BETWEEN ranges. Thanks!

  • 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-12T15:12:54+00:00Added an answer on June 12, 2026 at 3:12 pm

    Probably easier to use a UNION statement:

    SELECT 
      zip, city, state, avg_agi, 0 AS distance 
    FROM 
      zip_codes, avgagi 
    where 
          zip=zipcode 
    UNION
    SELECT 
      zip, city, state, avg_agi, 
      ( 3959 
          * acos( 
                  cos( radians(34.088808) ) 
                * cos( radians( lat ) ) 
                * cos( radians( lng ) - radians(-118.40612) ) 
                + sin( radians(34.088808) ) 
                * sin( radians( lat ) ) 
            ) 
      ) AS distance 
    FROM 
      zip_codes, avgagi 
    where 
          zip=zipcode 
      and avg_agi BETWEEN 100000 and 200000 
    HAVING 
      distance < 5 ORDER BY distance LIMIT 0 , 10000;
    

    otherwise try this:

    SELECT 
          zip, city, state, avg_agi, 
          ( 3959 
              * acos( 
                      cos( radians(34.088808) ) 
                    * cos( radians( lat ) ) 
                    * cos( radians( lng ) - radians(-118.40612) ) 
                    + sin( radians(34.088808) ) 
                    * sin( radians( lat ) ) 
                ) 
          ) AS distance 
        FROM 
          zip_codes, avgagi 
        where 
              zip=zipcode 
        AND(zip = 90210
        OR avg_agi BETWEEN 100000 and 200000 )
        HAVING 
          distance < 5 ORDER BY distance LIMIT 0 , 10000;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a zip file which has one base folder inside it with other
My base class has properties that are used by a subclass. where should Release
Is there a consistent code-base that allows me to upload a zip file to
Has any one used BITs in VB.NET? If so, do you have code samples
I'm working in MySQL with PHP. I'm doing a query for a zip code
ActiveRecord::Base has a big ol' API with multiple methods for both finding and saving
I'm trying to write out a zip file using the wxZipOutputStream. The code is
I have this domain model: class Person < ActiveRecord::Base composed_of :address, mapping: [%w(address_street street),
I'm attempting to utilize some code found here: http://androidtabs.googlecode.com/svn/trunk/ This includes the bases classes
I'm trying to write some python code which can create multipart mime http requests

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.