Home  >  Article  >  Backend Development  >  mysql查询语句,弄了一个小时也没解决

mysql查询语句,弄了一个小时也没解决

WBOY
WBOYOriginal
2016-06-23 13:49:14757browse

数据库mysql
表tb,有一个title字段
有一条记录为“峨眉山、乐山品质二日游 ”
另一条记录为“上海二日游 ”

有一固定字符串为"峨眉山,上海,成都,乐山,北京”
请问要怎么写一条语句能够查询诸如title字段包含有"峨眉山 or 乐山",或"上海"。
select * from tb where ??


回复讨论(解决方案)

select * from tb where title REGEXP '峨眉山|上海|成都|乐山|北京'

select * from tb where title like '%峨眉山%' or title like '%乐山%' or title '%上海%'

http://www.phpthinking.com/archives/187

用like.

like啊,

二楼回答很详细了,必须like

select * from tb where title REGEXP '峨眉山|上海|成都|乐山|北京'


xuzuning完美解决了我的问题,like的确是可以,但是当有很多个要匹配的时候不可能like,like,like吧。
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn