Welcome Guest, Not a member yet? Register   Sign In
mysql 3 table join
#2

[eluser]Steve Grant[/eluser]
Should be. Using subqueries almost always slows the query down. Try to condense it down so the joins are all within the one query.

Something like

Code:
SELECT photos.*, COUNT(comments.id_photo) AS comments_count, COUNT(votes.id_photo) AS votes_count
FROM photos
LEFT JOIN comments ON photos.id_photo = comments.id_photo
LEFT JOIN votes ON votes.id_photo = photos.id_photo
GROUP BY photos.id_photo;

I've not tested that query, so give it a go and see if you still get the right output.


Messages In This Thread
mysql 3 table join - by El Forum - 07-15-2008, 08:48 AM
mysql 3 table join - by El Forum - 07-15-2008, 09:23 AM
mysql 3 table join - by El Forum - 07-15-2008, 11:49 AM
mysql 3 table join - by El Forum - 07-15-2008, 11:58 AM



Theme © iAndrew 2016 - Forum software by © MyBB