Meir
Meir

Reputation: 61

Comparing 2 columns in 2 tables in MySql

I'm new to mysql so maybe my question will sound very simple but if some body can help with this:

I need to search 2 columns and output 2 exact columns that have exact string, for example

column1       column2
 sun           sun

the problem with this code is that it find this column values too.

column1         column 2
 sun             sun
 somesun         sun

this is the code

SELECT tags.string, tag
FROM tags
INNER JOIN tastings 
ON tastings.tags LIKE CONCAT('%', tags.string, '%')

the '%' sandwiching don't help and when I remove one of them I don't get any result. for example:

ON tastings.tags LIKE CONCAT(tags.string, '%')

this code also don't give any results

ON tastings.tags = tags.string

Upvotes: 2

Views: 76

Answers (1)

Meir
Meir

Reputation: 61

I was wondering why this work good when I sandwiching it with '%', so some spaces must to be. then to check it I used trim() function. and it worked :)

what was confusing is that CSV file don't have any spaces

so this is the final code that work:

SELECT tags.string, tag
FROM tags
INNER JOIN tastings 
ON tastings.tags = trim(tags.string)

Thanks to all who tried to help :)

Upvotes: 1

Related Questions