12

我正在使用带有 like 子句的内部联接..

我试过的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

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

4

3 回答 3

34

您必须使用 concat ...

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

+mysql中没有这样的运算符

于 2013-06-08T19:45:25.067 回答
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||'%'); 
于 2013-06-09T11:52:39.090 回答
-1

MySQL的一个例子:

SELECT  tbl_songs.bus_name FROM tbl_songs , tbl_albums
WHERE tbl_songs.albums LIKE CONCAT('%',tbl_albums.name, '%');
于 2014-07-19T06:20:15.007 回答