mysql 字段间 模糊匹配like concat

一个简单的sql语句,查了一些资料:

1、SQL Server:(不解释)

SELECT PATINDEX('%M_rs%', 'The stars near Mars are far from ours');

SELECT CHARINDEX('Mars', ' The stars near Mars are far from ours');

 

2、mysql如下:

如下:两个表str1 ,str2

str1表

 

id name
1 aa
2 bb
3 ee

 

str2  表

id name
1 a

2

b

 

str2表中 name 匹配str1中的name

   尝试select a.id, a.name from str1 a ,str2 b where a.name like ‘%'+b.name+'%' 报错了!

正确:

select a.id, a.name from str1 a ,str2  b where a.name like concat(b.name, '%')

posted @ 2012-10-08 21:37  苏梳  阅读(3552)  评论(0)    收藏  举报