How to make a "select like" to a subquery result

Asked

Viewed 985 times

3

I need to make a select in sql server 2014 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 subquery (select * from tabela1) in order to obtain the following result:

1
2
3
4
5

1 answer

1


You can make a Join:

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.