How to do a "select like" to a result of a subquery

3

I need to make a select in sql server 2014 to the result of a subquery, example:

select * from tabela2 where codigo like ("1;3;4","3","1;2;5")

Where ( "1;3;4","3","1;2;5" ) is the result of the subquery ( select * from tabela1 ) in order to get the following result:

1
2
3
4
5
    
asked by anonymous 27.09.2017 / 17:06

1 answer

1

You can join:

SELECT t.* 
FROM tabela2 t
INNER JOIN (SELECT codigo
            FROM tabela1
            GROUP BY codigo) E
    ON t.codigo LIKE '%' || E.codigo|| '%'
    
27.09.2017 / 18:28