您正在搜索文字字符串a.company
,而不是列。尝试这个:
SELECT a.id, a.company, a.name, b.title, b.description, b.t_id
FROM a, b
WHERE
(
b.title REGEXP concat('[[:<:]]', a.company, '[[:>:]]')
OR b.description REGEXP concat('[[:<:]]', a.company, '[[:>:]]')
OR b.title REGEXP concat('[[:<:]]', a.name, '[[:>:]]')
OR b.description REGEXP concat('[[:<:]]', a.name, '[[:>:]]')
)
AND a.company != '' AND a.name != ''
这提供了regexp
使用列的值,而不是字符串'a.company'
。因为我的猜测是您想要比较列值(而不是列名称),所以您需要连接您的regexp
一起。
您可以使用以下查询进行测试:
select
'My col: a.company' as Test1,
'My col: ' + a.company as Test2
from
a
Here, Test1
永远是价值My col: a.company
,而 Test2 将是My col: <company col value here>
.