查找精确匹配记录和字符串包含第1列的行字

时间:2019-12-17 21:14:01

标签: mysql sql

我有2列abc和bcd,我想将abc数据与bcd列完全匹配,并且句子包含abc。

I have 2 columns abc and bcd i want to compare abc data with bcd column exact match and sentence contain word

预期结果

enter image description here

2 个答案:

答案 0 :(得分:1)

您是否要选择所有存在abc匹配行bcd的行的所有行?然后使用EXISTS

select *
from mytable
where exists
(
  select null
  from mytable other
  where mytable.bcd like concat('%', other.abc, '%')
)
order by abc, bcd;

答案 1 :(得分:0)

您可以这样实现:

SELECT * FROM table_name WHERE table_name.abc like  CONCAT('%', table_name.bcd, '%');

这将返回所有记录,其中abc列的字符串中包含bcd列的字符串。

当然,用您的表名替换table_name

相关问题