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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:50:32+00:00 2026-06-11T09:50:32+00:00

I am trying to join 4 fields from the same table twice with a

  • 0

I am trying to join 4 fields from the same table twice with a table. I tried using two LEFT JOIN’s and also two WHERE statements as below. Currently I am just not getting any results for the g2.address, g2.latitude, g2.longitude, g2.method. Not sure If I am doing something wrong with the statement or just some other obvious mistake related to my data. Any help would be appreciated.

1st Attempt:

SELECT p.q_id, p.first_name, p.surname, p.gender, p.age, p.race, 
       p.q2_7, p.q2_8_1, p.q2_8_2, p.q2_8_3, p.q2_8_4, p.q2_8_5, 
       p.q2_8_6, p.q2_8_7, p.q2_8_8, p.q2_9, p.q2_10, p.q2_11, 
       p.q2_11_1_1, p.q2_11_1_2, p.q2_11_1_3, p.q2_11_1_4, 
       p.q3_1, p.q3_2, p.q3_2_1, p.q3_3, p.q3_4, p.q3_5, 
       g1.address, g1.latitude, g1.longitude, g1.method, 
       p.q3_7, p.q3_8, p.q3_9, p.q3_10, p.q3_11_1, p.q3_11_2, 
       p.q3_11_3, p.q3_12, p.q3_13, p.q4_1, 
       g2.address, g2.latitude, g2.longitude, g2.method, 
       p.q4_3, p.q4_4, p.q4_5, p.q5_0_1, p.q5_0_2, p.q5_0_3, 
       p.q5_1, p.q5_2, p.q5_3
  FROM people AS p 
  LEFT JOIN gmap_address_list AS g1 ON p.q3_6 = g1.id 
  LEFT JOIN gmap_address_list AS g2 ON p.q4_2 = g2.id 
 GROUP BY p.q_id

2nd Attempt

SELECT p.q_id, p.first_name, p.surname, p.gender, p.age, p.race, 
       p.q2_7, p.q2_8_1, p.q2_8_2, p.q2_8_3, p.q2_8_4, p.q2_8_5, 
       p.q2_8_6, p.q2_8_7, p.q2_8_8, p.q2_9, p.q2_10, p.q2_11, 
       p.q2_11_1_1, p.q2_11_1_2, p.q2_11_1_3, p.q2_11_1_4, p.q3_1, 
       p.q3_2, p.q3_2_1, p.q3_3, p.q3_4, p.q3_5, 
       g1.address, g1.latitude, g1.longitude, g1.method, 
       p.q3_7, p.q3_8, p.q3_9, p.q3_10, p.q3_11_1, p.q3_11_2, 
       p.q3_11_3, p.q3_12, p.q3_13, p.q4_1, 
       g2.address, g2.latitude, g2.longitude, g2.method, 
       p.q4_3, p.q4_4, p.q4_5, p.q5_0_1, p.q5_0_2, p.q5_0_3, 
       p.q5_1, p.q5_2, p.q5_3
  FROM people p, gmap_address_list g1, gmap_address_list g2 
 WHERE p.q3_6 = g1.id AND p.q4_2 = g2.id 
 ORDER BY p.q_id
  • 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-11T09:50:34+00:00Added an answer on June 11, 2026 at 9:50 am

    Without understanding exactly how p.q3_6 and p.q4_2 get populated, it’s hard to guess why your second LEFT JOIN might not match anything. But, you do have some duplicate column names in your queries’ result sets; this might baffle the array-loading stuff in php. You might try the following:

    SELECT ... ,
           g1.address AS g1_address, g1.latitude AS g1_latitude, 
           g1.longitude AS g1_longitude, g1.method AS g1_method, 
           ... ,
           g2.address AS g2_address, g2.latitude AS g2_latitude, 
           g2.longitude AS g2_longitude, g2.method AS g2_method, 
           ...
    

    Note, your second query: no good for a left join. Stick with the first one.

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

Sidebar

Related Questions

I need a join that yields three fields with the same name from two
I am trying to join my users table with another table using the following
I am trying to join 3 table in LINQ. var fromCities = from c
I am trying to join two EJB's using EJBQL (with an underlying MySQL data
I've trying to do an inner join select statement where I select two fields
I'm trying to update row in a table using values from a different row
Hi I am trying to join two bits of information on an MVC view
I have been trying to join two tables (USERS AND USERS_ROLES) based on their
I am trying to join two tables; the purpose being able to search and
If I run the two statements in batch will they return one table 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.