Sankalp
Sankalp

Reputation: 1350

Inner join with like clause

I am using inner join with the like clause ..

My tried sql is

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 + '%'; 

Its showing me syntax error.

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.

Upvotes: 13

Views: 24761

Answers (3)

Vinod Joshi
Vinod Joshi

Reputation: 7852

An example of MySQL:

SELECT  tbl_songs.bus_name FROM tbl_songs , tbl_albums
WHERE tbl_songs.albums LIKE CONCAT('%',tbl_albums.name, '%');

Upvotes: -1

rcmuthu786
rcmuthu786

Reputation: 130

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||'%'); 

Upvotes: 1

The Surrican
The Surrican

Reputation: 29856

you have to form the clause using concat ...

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

there is no + operator like this in mysql

Upvotes: 36

Related Questions