pckabeer
pckabeer

Reputation: 694

Mysql using like with two variables in different tabel

I have two tables a and b.

Table a has a field named gr which can have multiple values concatained with string.

Table b holds it seperately in fields lg.

How do i run the below query to check whether b.lg is in a.gr?

 SELECT lg FROM `a`,`b` WHERE a.`id` =22 AND  (a.gr LIKE '%'+b.lg+'%')

Upvotes: 0

Views: 179

Answers (1)

Omesh
Omesh

Reputation: 29081

You need to use CONCAT function try:

SELECT lg 
FROM a, b 
WHERE a.id = 22 AND  
      a.gr LIKE CONCAT('%', b.lg, '%');

Upvotes: 1

Related Questions