开发者

mysql 'WHERE' with 500 'OR's?

Is it ok to have a WHERE statement with a lot of OR's? I imagine the most could ev开发者_如何学JAVAer be 500.

I am dealing with a facebook app. Understandably (but annoyingly) they do not allow app developers to store friend relationships. As a result I can not do a sensible JOIN tblfriend or something along those lines.

To get a list of friends you can query facebook using FQL... that will return an array of facebook user ids. My thinking was to find a users most recent friend I could run a query like this:

'SELECT * FROM user WHERE fb_id = ' . implode('OR fb_id = ', $friend_array) . ' ORDER BY created LIMIT 0,1'; 

Is there a better way?


you could use an IN clause


as Marek Karbarz said, use IN :

'SELECT * FROM user WHERE fb_id IN (' . implode(',', $friend_array) . ') ORDER BY created LIMIT 0,1'; 


Use the IN contruct.

..WHERE fb_id IN (1,2,3)

is the same as

..WHERE fb_id = 1 OR fb_id = 2 OR fb_id = 3
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜