pengu Posted January 21, 2010 Share Posted January 21, 2010 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! Quote Link to comment https://forums.phpfreaks.com/topic/189376-mulitple-inner-joins/ Share on other sites More sharing options...
Mchl Posted January 21, 2010 Share Posted January 21, 2010 Yes, it is possible to have multiple JOINS in one query. Just make sure your syntax is correct. Quote Link to comment https://forums.phpfreaks.com/topic/189376-mulitple-inner-joins/#findComment-999657 Share on other sites More sharing options...
pengu Posted January 22, 2010 Author Share Posted January 22, 2010 Could you give me a little example of the correct syntax? Quote Link to comment https://forums.phpfreaks.com/topic/189376-mulitple-inner-joins/#findComment-999670 Share on other sites More sharing options...
Mchl Posted January 22, 2010 Share Posted January 22, 2010 SELECT t1.id, t1.info, t2.description, t3.example FROM table1 AS t1 INNER JOIN table2 AS t2 ON t1.id = t2.id INNER JOIN table3 AS t3 ON t2.id = t3.id Quote Link to comment https://forums.phpfreaks.com/topic/189376-mulitple-inner-joins/#findComment-999744 Share on other sites More sharing options...
pengu Posted January 22, 2010 Author Share Posted January 22, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/189376-mulitple-inner-joins/#findComment-999752 Share on other sites More sharing options...
gizmola Posted January 22, 2010 Share Posted January 22, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/189376-mulitple-inner-joins/#findComment-999753 Share on other sites More sharing options...
Mchl Posted January 22, 2010 Share Posted January 22, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/189376-mulitple-inner-joins/#findComment-999763 Share on other sites More sharing options...
pengu Posted January 25, 2010 Author Share Posted January 25, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/189376-mulitple-inner-joins/#findComment-1001077 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.