Which is more efficient in mysql, a big join or multiple queries of single table?
Posted
by
Tom Greenpoint
on Stack Overflow
See other posts from Stack Overflow
or by Tom Greenpoint
Published on 2011-01-13T15:50:44Z
Indexed on
2011/01/13
15:53 UTC
Read the original article
Hit count: 163
mysql
I have a mysql database like this
Post – 500,000 rows (Postid,Userid)
Photo – 200,000 rows (Photoid,Postid)
About 50,000 posts have photos, average 4 each, most posts do not have photos.
I need to get a feed of all posts with photos for a userid, average 50 posts each.
Which approach would be more efficient?
1: Big Join
select * from post left join photo on post.postid=photo.postid where post.userid=123
2: Multiple queries
select * from post where userid=123
while (loop through rows) {
select * from photo where postid=row[postid]
}
© Stack Overflow or respective owner