Jump to content

Multi-table Join


Kovo
 Share

Recommended Posts

Hello, Im wondering if Im doing this 3 table join correctly. Using MyISAM if it makes any difference.Thanks!

SELECT b.Name, b.Id, c.Picture FROM table1 AS a JOIN table2 AS b JOIN table3 AS c WHERE a.col1 = X AND a.col3 = 1 AND b.Id = a.col2 AND c.Id = b.UserId LIMIT 8

Where X can be any integer. I renamed tables to generic table1, etc....

Link to comment
Share on other sites

That will work, but it's not very efficient. It will be better if you specify the join conditions when you do the join instead of in the WHERE clause, e.g.:SELECT b.Name, b.Id, c.Picture FROM table1 AS a JOIN table2 AS b ON b.Id = a.col2 JOIN table3 AS c ON c.Id = b.UserId WHERE ...

Link to comment
Share on other sites

That will work, but it's not very efficient. It will be better if you specify the join conditions when you do the join instead of in the WHERE clause, e.g.:SELECT b.Name, b.Id, c.Picture FROM table1 AS a JOIN table2 AS b ON b.Id = a.col2 JOIN table3 AS c ON c.Id = b.UserId WHERE ...
Thanks for the tip! I was wondering if there was a better way :)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...