How to join tables in varchar fields in MySQL

Table_1
type   |   description
Error      Some description
Success    Another description

Table_2
type   |   description
Error 1    Some description
Error 2    Another description
Error 3    Yet another description

      

I need to concatenate these two tables in a type field which is a varchar datatype in both tables. The problem is that since "Error" is not the same as "Error 1" or "Error 2", when I compare both fields, it returns empty results. I tried:

select * from Table_1 a
left join Table_2 using (type)

select * from Table_2
where type in (select distinct type from Table_1)

      

Any help would be much appreciated, thanks in advance

EDIT: I should be able to get results when the type in table_1 is contained in the type in table_2. I know this is a little tricky to get, but the point is that in Table_1 I have common errors for different scenarios, and Table_2 contains the same errors, but with a little more information next to them. Table_2 is populated with data coming from log files and there is pretty much everything I can do about it.

+3


source to share


1 answer


Your connections should be fine. Third way:

select * from Table_1 a
left join Table_2 b on a.type = b.type

      

If you don't get any results, the column values type

are not equal.

Update



Considering that your comment states what Table_1.type

is a substring Table_2.type

, you can change the join operator:

select * from Table_1 a
left join Table_2 b on b.type LIKE '%' + a.type + '%'

      

This practice is not ideal. Use with caution.

+5


source







All Articles