Jump to content

Multi-table Join


Kovo

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...