Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using LIKE %% with LEFT JOIN

Tags:

sql

mysql

Ok, i used "LIKE" with "LEFT JOIN" and it works fine.

$sql = $conn->query("SELECT * FROM tasks t 
                     LEFT JOIN users u 
                     ON t.allowed_countries LIKE u.country 
                     WHERE u.username = '$username'");

but when i'm try to use "LIKE %%" instead of using "LIKE" then it gives me error

LIKE '%" u.country "%'

Can anybody tell me the problem please?

Thank you.

like image 484
user2203703 Avatar asked Dec 05 '22 23:12

user2203703


1 Answers

USE concat as % is a char literal.

LIKE concat('%',u.country,'%')
like image 83
radar Avatar answered Dec 20 '22 09:12

radar