O B
O B

Reputation: 21

How do I search using LIKE and wildcards in mysql?

LEFT JOIN schools ON (bt.MidSchool LIKE schools.Name OR **%schools.Name% LIKE bt.ElmSchool**) WHERE ...

This is the portion of my SELECT that I have problems with.

I would like to find if the string in column schools.Name exist in column bt.ElmSchool

When I add % before and after the column name %schools.Name% I get a syntax error. if I use '%schools.Name%' the query is perform but it's looking for the column name instead of its value. I have tried escaping but didnt work. any idea??

Upvotes: 2

Views: 70

Answers (1)

Tomalak
Tomalak

Reputation: 338208

  ...
  LEFT JOIN schools ON bt.MidSchool LIKE schools.Name 
                       OR bt.ElmSchool LIKE '%' + schools.Name + '%'
WHERE
  ...

Upvotes: 5

Related Questions