SQL Join with Like?

I struggled to find a good answer of how you can do an SQL join with LIKE (i.e. SQL join using properties from the table/using table variables). I was trying stuff like the below, to no avail:

...
FROM something AS s
JOIN another AS a ON s.one = a.one
  AND s.string LIKE ('%' + a.string + '%')
...

The answer was staring me in the face all the time (via a colleague):

...
LEFT JOIN dthing AS d
ON n.name = d.specialName
AND INSTR(n.ipInterfaces,d.serverIP) > 0
...

Below is the definition of what INSTR does:
https://www.w3schools.com/sql/func_mysql_instr.asp

Image: SQL INSTR()


Comments