MySQL查询:从其他字段/表格中的CSV搜索单个字段中的多个字符串?

时间:2017-04-16 03:32:35

标签: mysql regex search

我有一个表,其中包含两个带有文本内容的TEXT字段,并且在一个单独的表中,一个字段包含逗号分隔的关键字值,这些关键字可以是多个单词。以下查询在我的WAMP中使用Appserv,在我们的Hostgator LAMP中不起作用......为什么??

SELECT 
    t.content_me, t.content_visitor, t.Id, exp.owner_user_id, exp.name
FROM (SELECT t.content_me, t.content_visitor
      FROM `texts` AS t 
      WHERE t.owner_user_id=1 *<== obviously this changes...*
      ORDER BY t.Id DESC) AS t 
INNER JOIN exp ON t.Id = exp.owner_user_id AND 
      t.content_me REGEXP (REPLACE(exp.keywords,',','|')) 
WHERE t.owner_user_id=e.owner_user_id=6 
ORDER BY t.Id DESC

此外,如果我在这部分中输入一个值:

t.content_me REGEXP (REPLACE(exp.keywords,',','|')) 

正如我们所说:

t.content_me REGEXP ('yeah|ok')

它适用于Hostgator。所以我想问题是REGEXP(REPLACE(exp.keywords,&#39;,&#39;,&#39; |&#39;))东西......对吧?

修改

好的,我简化了查询只是为了它的乐趣:)

SELECT 
    t.Id,  t.text,  t.owner_user_id FROM `t` 
LEFT JOIN e ON e.owner_user_id = t.owner_user_id 
WHERE  
    t.text REGEXP REPLACE(e.keywords,',','|') AND t.owner_user_id=1

相同的结果:在WAMP中工作,在LAMP中不起作用。如果我像

那样做文字REGEXP
REGEXP REPLACE('yeah,can',',','|')

适用于两台服务器。

我的猜测是发生了什么事
REGEXP REPLACE(e.keywords,',','|')

,即让REGEXP使用字段内容而不是文字刺痛。

编辑:

嗯......现在我看到LAMP MySQL抛出一个错误(在WAMP中没有发生):

非法混合归类(utf8_general_ci,IMPLICIT)和(utf8_unicode_ci,IMPLICIT)用于操作&#39; regexp&#39;

...所以

 REGEXP REPLACE(e.keywords,',','|') COLLATE utf8_unicode_ci

修正了它

0 个答案:

没有答案