内连接,带like子句 [英] Inner join with like clause

查看:140
本文介绍了内连接,带like子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将内部联接与lik​​e子句一起使用..

I am using inner join with the like clause ..

我尝试过的sql是

SELECT tbl_songs.id    AS sid, 
       tbl_songs.name  AS sname, 
       tbl_albums.id   AS aid, 
       tbl_albums.name AS aname 
FROM   tbl_songs 
       INNER JOIN tbl_albums 
               ON tbl_songs.albums LIKE '%' + tbl_albums.name + '%'; 

它向我显示语法错误.

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '+ tbl_albums.name + '%'' at line 2

请详细说明语法错误的原因.

Please elaborate reason of syntax error.

推荐答案

您必须使用concat形成子句...

you have to form the clause using concat ...

...LIKE CONCAT('%',tbl_albums.name, '%');

在mysql中没有这样的+运算符

there is no + operator like this in mysql

这篇关于内连接,带like子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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