sql 匹配多字段简化

匹配多个字段,匹配多个字符串。

原始like:

SELECT * FROM article WHERE 
(
  title LIKE "%车%" 
  OR subtitle LIKE "%车%" 
  OR tag LIKE "%车%" 
) OR (
  title LIKE "%摩托%" 
  OR subtitle LIKE "%摩托%" 
  OR tag LIKE "%摩托%" 
) OR (
  title LIKE "%红色%" 
  OR subtitle LIKE "%红色%" 
  OR tag LIKE "%红色%" 
) OR (
  title LIKE "%美国%" 
  OR subtitle LIKE "%美国%" 
  OR tag LIKE "%美国%" 
) OR (
  title LIKE "%2006%" 
  OR subtitle LIKE "%2006%" 
  OR tag LIKE "%2006%" 
)

简化like

SELECT * FROM article WHERE 
CONCAT_WS(" ", title, subtitle, tag) REGEXP "车|摩托|红色|美国|2006"

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注