Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL: Join tables on substrings

I have a table A with the string-column a and a table B with the string-column b. a is a substring of b. Now I want to join the the two tables on a and b. Is this possible?

I want something like this:

Select * from A,B where A.a *"is substring of"* B.b

How can I write this in SQL (Transact-SQL)?

like image 366
Elmex Avatar asked Mar 20 '12 14:03

Elmex


1 Answers

You can use like

select *
from A
  inner join B 
    on B.b like '%'+A.a+'%'
like image 200
Mikael Eriksson Avatar answered Sep 22 '22 07:09

Mikael Eriksson