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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:11:08+00:00 2026-06-17T06:11:08+00:00

I’m trying to join 4 tables, two 1-N ones and one through an N-N

  • 0

I’m trying to join 4 tables, two 1-N ones and one through an N-N table. Strangely mySql doesn’t seem to like one of my syntaxes. Does anybody know if this is due to myOwn limitations or mySql?

This doesn’t work:

SELECT *
FROM tableOne t1 JOIN tableTwo t2 
    LEFT OUTER JOIN N_N_tableThree t3 
            JOIN tableFour t4 ON t4.id = t3.fk_tableFour
        ON t2.id = t3.fk_tableTwo
    ON t2.id = t1.fk_tableTwo

While this does work

SELECT *
FROM tableOne t1,
tableTwo t2 LEFT OUTER JOIN N_N_tableThree t3 
        JOIN tableFour t4 ON t4.id = t3.tableFour_id
    ON t2.id = t3.tableTwo_id
WHERE t2.id = t1.tableTwo_id

Anybody a clue?

Thanks for answering.

  • 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-17T06:11:09+00:00Added an answer on June 17, 2026 at 6:11 am

    Use this syntax instead:

    SELECT *
    FROM tableOne            t1 
    INNER JOIN tableTwo      t2 ON t2.id = t1.fk_tableTwo
    LEFT JOIN N_N_tableThree t3 ON t2.id = t3.fk_tableTwo
    INNER JOIN tableFour     t4 ON t4.id = t3.fk_tableFour;
    

    This will be equivalent of the second query that worked.

    Because the WHERE t2.id = t1.tableTwo_id in the second query is actually an INNER JOIN1, which will be the same as INNER JOIN tableTwo t2 ON t2.id = t1.fk_tableTwo as I did. This is the old JOIN syntax, try to avoid it and use the ANSI SQL-92 syntax instead as I did. For more information see this:

    • Bad habits to kick : using old-style JOINs.

    The query you posted didn’t work, because it is not the correct syntax for JOIN in MySQL, you have three ON clauses after each others:

    ...
    ON t4.id = t3.fk_tableFour
    ON t2.id = t3.fk_tableTwo
    ON t2.id = t1.fk_tableTwo
    

    Each JOIN should has the join condition specified with the ON clause after the JOIN directly, if not it would a cross join2. But not multiple ON‘s the way you did.

    SQL Fiddle Demo


    1: Don’t be confused with the use of INNER JOIN instead of JOIN they are the same the default JOIN is inner join, I just I used for readability. Also, the same thing with the OUTER keyword, I omit it in LEFT JOIN since it is optional when using LEFT or RIGHT

    2: You will find other variations of the JOIN syntax in MySQL in the reference page, like the JOIN tablename without a join condition, and others. You might need to read them.

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

Sidebar

Related Questions

I am trying to render a haml file in a javascript response like so:
I've tracked down a weird MySQL problem to the two different ways I was
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to loop through a bunch of documents I have to put
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.

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.