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

  • Home
  • SEARCH
  • 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 931251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:28:10+00:00 2026-05-15T20:28:10+00:00

So I have 2 tables : route(#id) step(#id,route_id,lat,lng,sequence_order) And 2 GPS coordinates : M1(lat1,

  • 0

So I have 2 tables :

route(#id)
step(#id,route_id,lat,lng,sequence_order)

And 2 GPS coordinates : M1(lat1, lng1) M2(lat2, lng2).

So I want to find all the routes which have at least one step closer than 1.0 mile from each of the 2 GPS coordinates with a ascending sequence order.

So if I find Route#25 which has a step S1 at 0.4 miles from M1, and a step S2 at 0.2 miles from M2, it should match only if the sequence number of S1 is inferior to the sequence number of S2. Does it make sense ?

Assuming I added a function to calculate the distance, I can do it quite easily with this request :

SELECT r.id,s1.lat,s1.lng,s2.lat,s2.lng,distance(s1.lat,s1.lng,lat1,lng1) as d1,distance(s2.lat,s2.lng,lat2,lng2) as d2 FROM route r
INNER JOIN step s1 ON r.id = s1.route_id
INNER JOIN step s2 ON r.id = s2.route_id AND s1.sequence_order < s2.sequence_order
WHERE d1<1.0
AND d2<1.0 

The behavior I would like to have, is to keep only the closest coordinates (s1.lat,s1.lng) and (s2.lat,s2.lng) to my to points. So I thought I could do something like this :

ORDER BY d1
ORDER BY d2
GROUP BY r.id

but it just crashes.

Any idea ?

  • 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-15T20:28:10+00:00Added an answer on May 15, 2026 at 8:28 pm

    You probably want

    ORDER BY d1, d2
    

    as your order by clause. What’s the crash, anyway?

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

Sidebar

Related Questions

I have those tables Node (#id, route_id, lat, lng) Route(#id) And I have four
I have two tables Route and Booking CREATE TABLE Route ( RouteID numeric(4), RouteIMG
I have two tables, one for routes and one for airports. Routes contains just
I have a table called routes within my database where each route has an
I have tables A and B with identity PKs ida and idb : ex
I have tables like these two test_table date student test 2012-05-31 Alice Math 2012-05-31
I have tables like this: tblUsers int UserID string UserName tblUsersInRoles int UserID int
I have tables linked by FK, I query on the first table using entity
I have tables named news and tags_news. Given a news id I have to
I have tables Product ( ID, CategoryID, ... ) Category ( ID, Name, ..

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.