Reputation: 1754
I want to join two tables on a like
clause. My schema is as the link:
As you can see the result is empty.
But if I use like
as follows:
As you see I can get the results with name
or des
contains 'GRE'. So what's the problem here?
I searched the answer for a while, and found the suggested way to do this is the same as I did:
Any suggestions will be highly appreciated.
Upvotes: 1
Views: 271
Reputation: 1123
You are doing it correctly. you just have to use TRIM()
to remove trailing whitespaces. Use it like
SELECT
a.id as app_id,a.app_name,a.des,
b.id as tag_id, b.name as tag_name
FROM aa_t_aaaa_app a
JOIN aa_t_aaaa_tag b
ON ((a.app_name LIKE CONCAT('%', TRIM(b.name) ,'%')) or (a.des Like CONCAT('%', TRIM(b.name) ,'%')))
order by a.id`
Upvotes: 6