sql – How to "select like" a result of a subquery

Question:

I need to make a select in sql server 2014 to the result of a subquery, for 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 obtain the following result:

1
2
3
4
5

Answer:

You can join:

SELECT t.* 
FROM tabela2 t
INNER JOIN (SELECT codigo
            FROM tabela1
            GROUP BY codigo) E
    ON t.codigo LIKE '%' || E.codigo|| '%'
Scroll to Top
AllEscort