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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:31:35+00:00 2026-05-17T22:31:35+00:00

I am LEFT JOINing multiple tables as such: SELECT * FROM table1 LEFT JOIN

  • 0

I am LEFT JOINing multiple tables as such:

SELECT * FROM table1
LEFT JOIN table2 ON table1.id = table2.fid
LEFT JOIN table3 ON table1.id = table3.fid
LEFT JOIN table4 ON table1.id = table4.fid
LEFT JOIN table5 ON table1.id = table5.fid
LEFT JOIN table6 ON table1.id = table6.fid
WHERE table2.id = '5184'

Reason being is simply because I tried regular JOIN and no results are returned unless at least one record exists in tables1-6 which is often not the case. As it stands this returns the info I want, but the problem is that a lot of the field names repeat and when I do a ‘mysql_fetch_array()’ in PHP it hides any field with a duplicate name.

What type of query can I do to avoid this? At the very least, how do I construct the query such that it doesn’t include all the double fields which are NULL?

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-05-17T22:31:36+00:00Added an answer on May 17, 2026 at 10:31 pm

    I can’t help but notice that you aren’t selecting anything from your left joined tables. It’s my understanding that joins are typically used to pull data from secondary tables where something in those tables matches a field in the primary table. I pulled this example from W3 schools:

    SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo
    FROM Persons
    LEFT JOIN Orders
    ON Persons.P_Id=Orders.P_Id
    ORDER BY Persons.LastName
    

    And unless this is a typo, you are selecting everything from table 1 where an id column = 5186 in table 2.

    You state that your query returns the info you want, but with many nulls and overwritten values. To fix this, I would restructure your query to follow the typical format shown above, and make sure you have a proper use of the left join statement.

    EDIT AFTER OP COMMENTS:

    You are naming a row id from table2, so I assume you should start by pulling fid from table 2 where table2.id = 5186, then left join from the other tables where table1.id = table2.fid.

    SELECT table2.fid, table1.id, table3.id, [add other tables here, and revise field names to select the ones you want]
    FROM table2
    LEFT JOIN table1 ON table1.id = table2.fid
    LEFT JOIN table 3 ON table3.fid = table1.id
    [add left joins to other tables here]
    WHERE table2.id = '5186'
    

    If this doesn’t help, I suggest being more specific towards what information the tables hold, and what you are searching for. A little more detail may help us help you.

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

Sidebar

Related Questions

When LEFT JOINing tables in a SQL query, sometimes I need to reference multiple
I have a MySQL Left Join problem. I have three tables which I'm trying
Given a DataSet, I'm left joining DataTables[1-n] onto DataTable[0]. I have created a method
SELECT i.*, i.id IN ( SELECT id FROM w WHERE w.status='active') AS wish FROM
Someone left the organisation but before leaving, he locked all the files for an
In IE6 the left of the #right-content DIV is cut off. I've been playing
On the left you will notice the google logo rendered by IE, I drew
The navigation on the left menu in the below site uses CSS for mouseover
Reading this post has left me wondering; are nightly builds ever better for a
How do you left pad an int with zeros when converting to a String

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.