Jump to content

Mulitple INNER JOIN's


pengu

Recommended Posts

Hello all, haven't posted for a while.

 

I did a quick search on this and found it for MySQL.

 

So I want to do something like..

 


SELECT table1.id, table1.info, table2.description, table3.example FROM table1 INNER JOIN table2 ON table1.id = table2.id

 

That much works, but not sure how to or if it is even possible to do another INNER JOIN.

 

Thank you for help!

Link to comment
Share on other sites

Bah.. this is what I did, the 'AS' is not needed, right?  It's just a mask for table name sort of thing?

 

Thanks for response anyways.

 

Yes it's optional, it aliases the table, so that you don't have to spell out the full table name all the time.  There are also times when you require an alias -- namely when you are joining a table to itself.

Link to comment
Share on other sites

Also if you're joining a subquery rather than actual table, you have to give it an alias.

 

SELECT
  t1.ID, t1.field1,
  sq.field2, sq.field3
FROM
  table1 AS t1
INNER JOIN (
  SELECT
     ID, field2, field3
  FROM
    someOtherTable
  WHERE
    someCondition = TRUE
) AS sq
ON
  t1.ID = sq.ID

Link to comment
Share on other sites

Thanks for the help guys.

 

Found the problem, I was editing a report created by someone else and some of the field names didn't have the table prefix at the front and it was clashing with the other tables.  All good now!

 

Solved.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.