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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:24:19+00:00 2026-05-31T07:24:19+00:00

I have the following tables: Table 1 – NODES (I access it through a

  • 0

I have the following tables:

  • Table 1 – NODES (I access it through a DB_LINK):

    SITE_ID    LATITUDE    LONGITUDE
    ABC123     21.018      -89.711
    CDE456     20.35       -87.349
    FGH789     20.258      -87.406
    ABB987     18.54       -88.302
    CFF546     18.542      -88.273
    GHT553     18.52       -88.311
    
  • Table 2 – LINKS

    ID   SITE_A    SITE_B   STATUS  NAME  LINK_TYPE REGION  ---> Many other fields
    1    ABC123    GHT553
    2    FGH789    CFF546     
    3    CDE456    ABC123        
    4    CFF546    GHT553     
    
  • Table 3 – RESULT (This is what I want to achieve) – No matter the order

    LINK_ID   SITE_A_ID   LAT_SITE_A   LON_SITE_A   SITE_B_ID   LAT_SITE_B   LON_SITE_B
    1         ABC123      21.018       -89.711      GHT553      18.52        -88.311
    2         FGH789      20.258       -87.406      CFF546      18.542       -88.273
    3         CDE456      20.35        -87.349      ABC123      21.018       -89.711
    4         CFF546      18.542       -88.273      GHT553      18.52        -88.311
    

(Plus several other fields, which means no trouble for me)

This is what I have tried:

SELECT RES2.*, SAM2.LATITUDE LAT_SITE_B, SAM2.LONGITUDE LON_SITE_B FROM(
    SELECT RES1.*, NOD.LATITUDE LAT_SITE_A, NOD.LONGITUDE LON_SITE_A FROM(
        SELECT ID, SITE_A, SITE_B, STATUS, NAME, LINK_TYPE FROM LINKS
            WHERE SITE_A IS NOT NULL AND SITE_B IS NOT NULL AND REGION IN (8,6)
         )RES1, NODES@NODES_DBLINK NOD WHERE RES1.SITE_A = NOD.SITE_ID
     )RES2, NODES@NODES_DBLINK NOD2 
WHERE RES2.SITE_B = NOD2.SITE_ID;

Until the SELECT RES1.\*, everything works fine, but when I add the SELECT RES2.\*, it takes too long without returning anything.

  • 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-31T07:24:21+00:00Added an answer on May 31, 2026 at 7:24 am

    From the textual part of your question, this query will generate the result you want:

    SELECT links.id AS link_id,
           node_a.site_id AS site_a_id,
           node_a.latitude AS lat_site_a,
           node_a.longitude AS lon_site_a,
           node_b.site_id AS site_b_id,
           node_b.latitude AS lat_site_b,
           node_b.longitude AS lon_site_b
      FROM links
     INNER JOIN nodes@nodes_dblink node_a ON (links.site_a = node_a.site_id)
     INNER JOIN nodes@nodes_dblink node_b ON (links.site_b = node_b.site_id)
     ORDER BY links.id;
    

    From the query you posted it seems you have some other criteria to include too which might mean you want something more like this:

    SELECT links.id AS link_id,
           node_a.site_id AS site_a_id,
           node_a.latitude AS lat_site_a,
           node_a.longitude AS lon_site_a,
           node_b.site_id AS site_b_id,
           node_b.latitude AS lat_site_b,
           node_b.longitude AS lon_site_b
      FROM links
     INNER JOIN nodes@nodes_dblink node_a ON (links.site_a = node_a.site_id)
     INNER JOIN nodes@nodes_dblink node_b ON (links.site_b = node_b.site_id)
     WHERE links.site_a IS NOT NULL
       AND links.site_b IS NOT NULL
       AND links.region IN (8, 6)
     ORDER BY links.id;
    

    Hope it helps…

    EDIT:
    If your DB link is an issue, try to return only the data you’re going to need over the link in advance either by creating a view on the remote DB or a materialised view on the local DB.
    If that isn’t practical then check the relative explain plans for the query above against this one and see if it is any better:

    WITH node_data
      AS (SELECT site_id,
                 latitude,
                 longitude
            FROM nodes@nodes_dblink node
           WHERE EXISTS (SELECT 1
                           FROM links
                          WHERE links.site_a = node.site_id
                             OR links.site_b = node.site_id))
    SELECT links.id AS link_id,
           node_a.site_id AS site_a_id,
           node_a.latitude AS lat_site_a,
           node_a.longitude AS lon_site_a,
           node_b.site_id AS site_b_id,
           node_b.latitude AS lat_site_b,
           node_b.longitude AS lon_site_b
      FROM links
     INNER JOIN node_data node_a ON (links.site_a = node_a.site_id)
     INNER JOIN node_data node_b ON (links.site_b = node_b.site_id)
     WHERE links.site_a IS NOT NULL
       AND links.site_b IS NOT NULL
       AND links.region IN (8, 6)
     ORDER BY links.id;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following tables CREATE TABLE `files` ( `fileid` int(11) NOT NULL AUTO_INCREMENT,
I have the following tables: CREATE TABLE title ( booktitle VARCHAR( 60 ), title_id
I have the following five tables: ISP Product Connection AddOn AddOn/Product (pivot table for
I have the following two tables, affiliates and referrers. affiliates Table id loginid 3
I have following situation. A main table and many other tables linked together with
I have the following tables: --table sportactivity-- sport_activity_id, home_team_fk, away_team_fk, competition_id_fk, date, time (tuple
I have the following tables: CREATE TABLE IF NOT EXISTS `Person_Categories` ( `PrsCatID` int(11)
I have the following tables: CREATE TABLE `attendance_event_attendance` ( `id` int(11) NOT NULL AUTO_INCREMENT,
Let's say you have the following two tables: X Table X_ID Y_ID_F X_Value 1
I have the following 3 tables: 1) Sweetness Table FruitIndex CountryIndex Sweetness 1 1

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.