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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:58:11+00:00 2026-05-24T20:58:11+00:00

I need to return all the entries in my database that are fairly close

  • 0

I need to return all the entries in my database that are fairly close to a given point. At the moment I am doing this (in the WHERE section):

OR (    
    (Addresses.Latitude IS NOT NULL)
    AND (Addresses.Longitude IS NOT NULL)
    AND ( Abs(Addresses.Latitude - @SearchInLat)  < 0.5)
    AND ( Abs(Addresses.Longitude - @SearchInLng) < 0.5)
)

I am doing manhattan distance rather than cartesian distance as my database has a large number of records, and calculating square roots is slow.

I’m pretty new to SQL databases, but I remember reading that it is considered very bad for efficiency to have functions inside SELECT procudures. Does this even apply for really simple functions such as taking the absolute value? Is something like:

OR (    
    (Addresses.Latitude IS NOT NULL)
    AND (Addresses.Longitude IS NOT NULL)
    AND ( (Addresses.Latitude - @SearchInLat)  < 0.5)
    AND ( (Addresses.Latitude - @SearchInLat)  > -0.5)
    AND ( (Addresses.Longitude - @SearchInLng) < 0.5)
    AND ( (Addresses.Longitude - @SearchInLng) > -0.5)
)

a better solution?

  • 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-24T20:58:12+00:00Added an answer on May 24, 2026 at 8:58 pm

    It is often not very efficient to have functions run on the data being returned – as in the case of your ABS. I don’t think you’re in any trouble in this case, however. You could avoid the use of the function by trying something like:

    OR (    
        (Addresses.Latitude IS NOT NULL)
        AND (Addresses.Longitude IS NOT NULL)
        AND ( (Addresses.Latitude - @SearchInLat) BETWEEN -0.5 AND 0.5)
        AND ( (Addresses.Longitude - @SearchInLng) BETWEEN -0.5 AND 0.5)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count a list of entries in my database that all have
I need a linq statement that returns all entries from a certain date. A
I need to write a query that returns all object less that or equal
In a shell-script (or Perl) I need a subroutine that returns for all my
Basically, the question says it all. I need a PL\SQL query that returns a
i need to return a JSON with this format: {answers: [{id: 93, value:Ahstron}, {id=94,
I need to return a full directory name from inside a specified directory that
In one of my Django projects that use MySQL as the database, I need
I need to get entries from database with counts of comments. Can i do
I have a query, that returns all entries, with unique datetime with ticks: select

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.