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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:58:18+00:00 2026-06-17T18:58:18+00:00

I have two tables, one that roughly looks like: client_ip server_ip speed ——— ———

  • 0

I have two tables, one that roughly looks like:

client_ip  server_ip  speed
---------  ---------  -----
1.2.3.4    9.1.2.3    100
1.2.3.5    9.1.2.3    1033

And another that has geo data:

ip       latitude    longitude
-------  --------    ---------
1.2.3.4  13.75       100.21
1.2.3.5  21.1234     141.21
9.1.2.3  13.75       99.21

I would like to write a select query that figures out the great circle distance between the two IP addresses, groups by it, and calculates the average speed. So, for example, the ideal output would be something like:

distance  avg(speed)
--------  ----------
21        99
100       1234

While I know there are good resources out there on getting the great circle distance in SQL, my head is a little cloudy on how to efficiently join the two tables, since both are rather large (millions of rows).

Any advice?

  • 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-17T18:58:19+00:00Added an answer on June 17, 2026 at 6:58 pm

    Assuming that the IPs in the geo data table are unique, it is actually not a very expensive join. Even though you are joining from a table with non-unique values in the server_ip column, you don’t have to tell the system that it is an outer join — for each line in the “speed” table, there will be one, and only one, entry in the IP table matching the client_ip, and one, and only one, entry in the IP table matching the server_ip. So, you can use inner joins without any trouble.

    SELECT <c.client_ip to s.server_ip distance calc> AS Distance, AVG(sp.speed) AS AvgSpeed
    FROM speedTable sp JOIN geoTable c
        ON sp.client_ip = c.client_ip JOIN geoTable s
        ON sp.server_ip = s.server_ip
    WHERE 1 = 1 --whatever your where clause is
    GROUP BY <c.client_ip to s.server_ip distance calc>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was making one table that have two foreign key to another tables. But
I have two tables, one that stores serial number uut_build , and another for
I have two tables, one that stores user earnings and another that stores the
I have two tables, one that holds lot of links (tvlinks), and another that
I have two tables one Employee and mailing Subscriptions Employee looks like this: Name
I have two tables, one that has 450 rows, the other is a Sort
I have two tables, one that has a foreign key from the other. I
I want to delete multiple records at once. I have two tables, one that
I have two tables that link together through an id one is submit_moderate and
Suppose I have two tables that are linked (one has a foreign key to

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.