小编典典

内连接,带like子句

sql

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

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

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


阅读 178

收藏
2021-04-22

共1个答案

小编典典

您必须使用concat形成子句…

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

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

2021-04-22