我正在使用类似子句的内部联接..
我试过的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
请详细说明语法错误的原因。
答案 0 :(得分:28)
你必须使用concat ...
形成子句...LIKE CONCAT('%',tbl_albums.name, '%');
在mysql
中没有这样的+
运算符
答案 1 :(得分:1)
You can use below format in oracle 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||'%');
答案 2 :(得分:-1)
MySQL的一个例子:
SELECT tbl_songs.bus_name FROM tbl_songs , tbl_albums
WHERE tbl_songs.albums LIKE CONCAT('%',tbl_albums.name, '%');