I’m building a Twitter application that grabs a users entire following and gets their specific id Ex: 1223455
I also have a huge database full of rows that contain a specific Twitter id… Look at the examples in rows…
|1| 122345 |
|2| 2232144 |
|3| 99653222 |
|4| 123232 |
|5| 2321323 |
|6| 3121322 |
The problem is we all know that Twitter is all about more and more followers (1,000’s), and I was wonder is this is a good MySQL query to run potentially up to 20 times in one script run…
SELECT * FROM table WHERE twitterID='132323' OR twitterId='23123' OR twitterId='23123' OR twitterId='23123' OR twitterId='23123' OR twitterId='23123' OR twitterId='23123' OR twitterId='23123
And on and on and on and on… There could potentially be over 1,000 OR statements in a single query (and a similar query like this could be called 20 times)
This doesn’t seem like a very good programming practice, but I haven’t heard of another way…??
2
Use the in
specifier:
Select * from table where twitterid in (123,456,789,...)
6
This is a very bad idea indeed. MySQL doesn’t do a good job with optimizing OR statements.
You’d be far better off using a JOIN or something like this
WHERE twitterId IN (
select *
from followers
where followee = whatever
)
Try this:
SELECT *
FROM table t1
WHERE twitterID
IN (select twitterID
from twitterIDsTable t2
where t1.twitterID = t2.twitterID)--for performance