tags:

views:

111

answers:

3

Is it ok to have a WHERE statement with a lot of OR's? I imagine the most could ever 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?

+5  A: 

you could use an IN clause

Marek Karbarz
+2  A: 

as Marek Karbarz said, use IN :

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

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
Yada