Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

212
Visualizações
Filter table to leave out specific rows

I have the table

| WorkerID | ProjectName |  Role  |
|----------|-------------|--------|
|     1    |    Test     | Leader |
|----------|-------------|--------|
|     4    |    Test     | Worker |
|----------|-------------|--------|
|     2    |    Stuff    | Leader |
|----------|-------------|--------|
|     3    |    Proj     | Worker |

and now I want to list every ProjectName where there is no specified Leader like this:

| ProjectName |
|-------------|
|    Proj     |

Right now I only know how to filter all ProjectNames with Leaders, but not the way to filter them the other way!

Any help is appreciated :)

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

One way to do it is with aggregation and the condition in the HAVING clause:

SELECT ProjectName
FROM tablename
GROUP BY ProjectName
HAVING SUM(Role = 'Leader') = 0;
over 4 years ago · Santiago Trujillo Relatório

0

(FYI: I'm mostly acquainted with PostgreSQL, so I'm not sure if this is completely transferrable)

I would do a subquery to identify the projects that have leaders, and in your main query, do a WHERE statement that selects all of the projects that are NOT IN the subquery.

SELECT ProjectName
FROM Table
WHERE ProjectName NOT IN (
  SELECT ProjectName
  FROM Table
  WHERE Role = 'Leader'
  )
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda