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
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?