MySQL喜欢多个值
我有这个MySQL查询。
我有这个内容的数据库字段
sports,shopping,pool,pc,games shopping,pool,pc,games sports,pub,swimming, pool, pc, games 为什么这样的查询不起作用? 我需要运动或酒吧或两个领域?
 SELECT * FROM table WHERE interests LIKE ('%sports%', '%pub%') 
	
  (a,b,c)列表仅适用于in 。 对于like ,你必须使用or : 
 WHERE interests LIKE '%sports%' OR interests LIKE '%pub%' 
这样做的更快的方法:
 WHERE interests LIKE '%sports%' OR interests LIKE '%pub%' 
这是:
 WHERE interests REGEXP 'sports|pub' 
在这里find这个解决scheme: http : //forums.mysql.com/read.php?10,392332,392950#msg-392950
更多关于REGEXP在这里: http ://www.tutorialspoint.com/mysql/mysql-regexps.htm
你为什么不尝试REGEXP。 试试像这样:
 SELECT * FROM table WHERE interests REGEXP 'sports|pub' 
 你的查询应该是SELECT * FROM `table` WHERE find_in_set("sports", interests)>0 
我所理解的是,你把兴趣存放在你的桌子的一个领域,这是一个误解。 你应该明确地有一个“兴趣”表。
 如果在AND参数之后使用此函数,请不要忘记使用圆括号 
喜欢这个:
 WHERE id=123 and(interests LIKE '%sports%' OR interests LIKE '%pub%') 
 像@Alexis Dufrenoy提出的,查询可以是SELECT * FROM `table` WHERE find_in_set('sports', interests)>0 OR find_in_set('pub', interests)>0 
手册中的更多信息。