Search Records that are not in another table

0

Good morning ..

I have table [BCT_PESSOA] with PK [ID_PESSOA] this table has relationship with table [BCS_USUARIO] with column [ID_PESSOA]

I would like to return all records in the [BCT_PESSOA] table that [ID_PESSOA] does not exist in the [BCS_USUARIO] table.

    
asked by anonymous 11.05.2017 / 18:20

2 answers

0
SELECT * FROM BCT_PESSOA p
inner join BCT_PESSOATIPO pt on pt.ID_PESSOA = p.ID_PESSOA
WHERE NOT EXISTS (SELECT * FROM BCS_USUARIO u WHERE p.ID_PESSOA = u.ID_PESSOA)
and pt.ST_TIPO = 'FUN'

I think this will solve

    
11.05.2017 / 18:34
1

Here is an example for the query.

   Select a.*
     from BCT_PESSOA a
left join BCS_USUARIO b on a.ID_PESSOA = b.ID_PESSOA
    where b.ID_PESSOA is null
    
11.05.2017 / 20:56