tags:

views:

80

answers:

1

Below is a mysql query I am working on for a page that hase User Status POst (like twitter in a way) Comments on these post User photo and name to show who posted the status post or the comment

The list of user ID's in the IN clause is generated from another query which is a large table around a million rows. Should I try to JOIN that table to the query below OR get those results seperate like I currently do and us them like shown below as a string of ID's?

SELECT s.statusid, s.userid, s.statustype, 
       s.subject, s.datetime, c.commentid, 
       c.statusid, c.userid, c.comment, c.datetime, 
       fru.disp_name, fru.pic_url
FROM teststatus AS s
LEFT JOIN teststatuscomments AS c ON s.statusid = c.statusid
LEFT JOIN friend_reg_user AS fru ON ( fru.auto_id = s.userid 
                                      AND fru.auto_id = c.userid ) 
WHERE s.userid =1
OR s.userid
IN ( 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 ) 
ORDER BY s.statusid
+1  A: 

It smells like something with your schema is not ok if you need to do such queries with large IN clauses.

You should rather join these rows instead of generating such a long IN statement. What's stored in these millions of rows?

tharkun
Well the first part of my question I figured out and it is in my updated query above, so the other part is just a question of should I add another join to this or not
jasondavis
THe million row table has a friend ID number, a user ID number, a status number and thats about it, it lets a user know who that user is friends with
jasondavis
ok thanks. so you only want the comments of the friends or only friends can post?
tharkun