Name table resulting from SELECT

0

I need to do a SELECT of the resulting table from another SELECT , but I need to reference it in ON INNER JOIN in>. How do I do this in Oracle (PL / SQL)? I tried this way, but it did not work:

SELECT * FROM (SELECT * FROM recurso WHERE tipo = 'CID') AS cidade INNER JOIN hierarquia ON hierarquia.recurso = cidade.codigo; 
    
asked by anonymous 22.11.2017 / 14:53

1 answer

1

You should position Subselect in front of INNER JOIN and then you can give your selection a nickname as if it were a table.

SELECT * 
FROM hierarquia 
INNER JOIN (
   SELECT *
   FROM recurso 
   WHERE tipo = 'CID'
) Cidade
ON Cidade.codigo = hierarquia.recurso 

SQLFiddle - Online sample

    
22.11.2017 / 15:06