Mysql, PHP, searching for multiple words

前端 未结 5 1053
有刺的猬
有刺的猬 2021-01-23 05:11

I\'m trying to search a table for specific words.

Say I have a list of words: printer,network,wireless,urgent

I only want to return those rows where all of these

5条回答
  •  清酒与你
    2021-01-23 06:06

    Alternative answer, just because I thought of it when I looked at your question. I do not know whether it would be faster than the other answers (most likely no):

    (SELECT * FROM tickets WHERE subject LIKE "%printer%" OR body LIKE "%printer%")
    UNION
    (SELECT * FROM tickets WHERE subject LIKE "%network%" OR body LIKE "%network%")
    UNION
    (SELECT * FROM tickets WHERE subject LIKE "%wireless%" OR body LIKE "%wireless%")
    UNION
    (SELECT * FROM tickets WHERE subject LIKE "%urgent%" OR body LIKE "%urgent%")
    

    UPDATE: This is wrong

提交回复
热议问题