MySQL:在LIKE上加入两个表 [英] MySQL: JOIN two tables on LIKE

查看:78
本文介绍了MySQL:在LIKE上加入两个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表,该表的列包含文本,我想选择所有表,其中第二个表中某一行的文本出现在该行中.这是一个伪查询:

I have a table with a column containing text, and I want to select all of the tables where the text from one of the rows in a second table appears in that row. Here is a pseudo-query:

SELECT title FROM recipes AS r 
   JOIN ingredients AS i 
   ON r.ingredients LIKE '%' + i.name + '%';

但是,以上查询不起作用.如何正确执行此操作?

The above query does not work, however. How do I do this correctly?

推荐答案

您不能使用+运算符连接字符串(仅用于算术运算).改为使用concat('%',i.name,'%').

You can't concatenate strings with the + operator (it's for arithmetic only). Use concat('%',i.name,'%') instead.

这篇关于MySQL:在LIKE上加入两个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆