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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:41:59+00:00 2026-06-17T15:41:59+00:00

I have a setup for 2 tables which is rather curious. Table A: it

  • 0

I have a setup for 2 tables which is rather curious.

Table A:
it has multiple columns, but is basically a collection of information.
Say:

------------------------------------
my_id| name | address | lat | long 

Table B is a long list of relationshisp between elements of table A:
For example:

------------------
my_id | parent_id

What I want to do is the following:

For any A.my_id, get the list of the B.my_id which have A.my_id as B.parent_id (there is also the case in which there’s noone) and then:

get, for each element in this list (we just got), lats and longs from table A for these ids and create an 2 array out of them.

Can anyone point me in the right direction? I am rather new to SQL and while I managed up ’til now, this really baffles me.

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-17T15:42:00+00:00Added an answer on June 17, 2026 at 3:42 pm
    SELECT results.lat, results.long 
    FROM a 
    JOIN b 
        ON b.parent_id=a.my_id 
    JOIN a AS results 
        ON results.my_id=b.my_id
    WHERE a.my_id = 'the one I'm looking for'
    

    Ignoring the selected columns for a minute, the query will give you rows from table A that match the particular ID you’re looking for (see the where clause), joined with rows from B that have the same parent ID as the ID you’re looking for, joined with table A again, this time rows that have an ID that matches the ID in B.

    If your tables look like this:

    TABLE A
    my_id| name | address | lat | long
      1    ABC    1234      10     20
      2    DEF    5678      15     19
      3    GHI    9101      17     21
      4    JKL    1121      18     18
     ...
    
    TABLE B
    my_id|parent_id
      1      4
      3      4
     ...
    

    If you do this query:

    SELECT *
    FROM a 
    JOIN b 
        ON b.parent_id=a.my_id 
    JOIN a AS results 
        ON results.my_id=b.my_id
    WHERE a.my_id = 4
    

    You should get these results:

    a.my_id | a.name | a.address | a.lat | a.long | b.my_id | b.parent_id | results.my_id | results.name | results.address | results.lat | results.long
       4       JKL       1121       18       18        1          4             1             ABC                   1234           10             20
       4       JKL       1121       18       18        3          4             3             GHI                   9101           17             21
    

    From there we just change the columns in the SELECT to affect what the results look like.

    The trick here is using the same table (A) in two places in the JOIN.

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

Sidebar

Related Questions

We have a database with a tables called 'Sites' This table has the columns,
I have two tables, one table has some information in each row along with
Curious whether folks have setup 2 way transactional replication on the tables ASP.NET uses
Here's my toy setup. I have 3 tables. One table is a guest list
I have a table with a few relational columns and one XML column which
I have setup 3 tables in symfony: A flipbook table, A Skills table, and
The Setup I have two tables, USERS and PETS . each user has an
I have the following setup (which works fine). Using CodeFirst (CTP4). A template has
i have a number of Tables setup in SQl Server i have transferred all
I need some advice of how to setup my tables I currently have a

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.