Problem with SELECT [duplicate]

1

I have the following SELECT

SELECT t.nome, count(t.id)
FROM Partidas p
LEFT JOIN Times t ON p.codTimeCasa = t.id
OR p.codTimeVisitante = t.id
GROUP BY t.nome

I would like it to return the teams that have no connection with the partidas table, however it only returns the ones it has, would anyone know how to solve this problem?

    
asked by anonymous 17.10.2016 / 01:59

1 answer

1

I believe that by using a subquery with NOT EXISTS, you can solve this.

SELECT t.nome, count(t.id)
FROM Partidas p
WHERE NOT EXISTS (SELECT NULL From Time t WHERE t.id = p.codTimeCasa OR t.id = p.codTimeVisitante)
GROUP BY t.nome

This link has more details: link

    
17.10.2016 / 02:31