exists doubtful

Dúvidas, dicas e truques de SQL, Select, Update, Delete, cláusulas, operações com joins, Funções em SQLs, etc
  

Poston Wed, 14 Nov 2007 12:33 pm

That's the way I can do a EXISTS?

SELECT * FROM USER where nrregistro exists (select * from user u where nrregitro = 48445)
carlos12
Location: rio

Poston Wed, 14 Nov 2007 12:42 pm

In this case doesn't make much sense, because you're doing EXISTS in the same table.
Hence it is better to put in the where clause.

Normally, I do a kind of \"JOIN\" between the external and internal table like this:
Code: Select all
SELECT *
FROM USUARIO U
WHERE exists (select 1
              from PERMISSAO P
              where u.usuario = p.usuario
                and u.permissoa='x'
             )
in this case, it will show all users who have permission to ' x '.
Now, a typical thing to do with exists:
Code: Select all
SELECT *
FROM USUARIO U
WHERE exists (select 1
              from PERMISSAO P
              where u.usuario = p.usuario
                and u.permissoa='x'
             )
  and exists (select 1
              from PERMISSAO P
              where u.usuario = p.usuario
                and u.permissoa='y'
             )
He will catch all users who have permission X and Y!
dr_gori
Location: Portland, OR USA

Thomas F. G

Você já respondeu a dúvida de alguém hoje?
http://glufke.net/oracle/search.php?search_id=unanswered

Poston Mon, 19 Nov 2007 6:59 am

Boy valews for your help now I understand more the exists brigadão that God bless you.
carlos12
Location: rio



Return to SQL

Who is online

Users browsing this forum: No registered users and 2 guests