Help with SQL query - delete a field/ occurrence

Asked

Viewed 31 times

0

I am trying to perform a query where all beings should be managers but they should not have worked on a project. It turns out that this john is the only being who works and manages a project and I must eliminate him from the query. But without success.

SELECT pessoa.primeiro_nome, projeto.nome
from pessoa INNER JOIN projeto 
ON pessoa.id = projeto.id and pessoa.id != projeto.pessoa_gerente_id
WHERE projeto.id <> projeto.pessoa_gerente_id

also tried with this select but john continues

select distinct * from pessoa
Join projeto on pessoa.id = projeto.pessoa_gerente_id
WHERE projeto.nome IS NOT NULL

Could someone shed some light on how to solve this problem?

Here you can check the bank script

I performed a consultation that returned all beings with their respective projects, and some were null, Is this an inconsistency, or is it correct?

  • 1

    In fact, beings should be managers, but they should never have worked on a project.

1 answer

0

  1. Present the names of managers who have never worked on projects, and manage them.
SELECT DISTINCT pes.primeiro_nome,
                pes.ultimo_nome
  FROM pessoa pes
 INNER JOIN projeto prj
    ON prj.pessoa_gerente_id = pes.id
 WHERE NOT EXISTS(SELECT 1
                    FROM projeto prj2
                   INNER JOIN pessoa_projeto pesprj
                      ON pesprj.pessoa_id = prj2.id
                   WHERE prj2.id <> prj.id)

I noticed that in the database you linked there is no record in the table pessoa_projeto, so all the managers will show up at query, since there is no one allocated in any project.

Browser other questions tagged

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