Search code examples
phpmysqlphpbb

How to match multiple field in mySQL


Im trying to match forum_id with several different forum_id's, something like forum_id = 5,7,12,43,63,78

I currently have this code:

SELECT topic_title, topic_id, forum_id 
FROM $MYSQL_TOPIC 
WHERE topic_title 
LIKE '%%%s%%' 
    AND forum_id = 5 
LIMIT 50

(using mysql_real_escape_string and sprintf)

I tried:

forum_id = 5 OR 7
forum_id = 5|7
forum_id = 5 AND 7
forum_id = 5 & 7

But none of them will match them all and therefore search though them all.


Solution

  • forum_id IN (5,7,12,43,63,78)