Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Sql join with like condition not working for non exact matches

I am trying to join my expenses table with like query to categorize them into defined categories. I am trying if my expenses table even have a mention of a full keyword from lookup table, it should categorize them. Example, it does not show ‘fine Esso brampton’ categorized as ‘Gas’. But the like join only works for exact match. Please suggest what’s the issue here:

SELECT expenses.Description, expenses.Amount, COALESCE(lookup.Category, 'Others') as Category
FROM expenses
LEFT join lookup ON lookup.Description LIKE CONCAT('%', expenses.Description,'%')

enter image description here

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

it seems to me or need to swap fields like

SELECT expenses.Description, expenses.Amount, COALESCE(lookup.Category, 'Others') as Category
FROM expenses
LEFT join lookup ON expenses.Description LIKE CONCAT('%', lookup.Description ,'%')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading