0
I have 2 tables city: id/idPreffect/idVice person: id/name The following select searches for me the name of the city and the name of the Mayor and his deputy...
SELECT cidade.nome,
ppref.nome as Prefeito,
pvice.nome AS Vice
FROM cidade
JOIN pessoa ppref ON cidade.idPrefeito = ppref.id
JOIN pessoa pvice ON cidade.idVice = pvice.id;
but when one of the two data is null it does not return anything, as I do for If idmayor and/ or idvice is equal to null it returns "Vago" and continues to bring the rest ??
Exchange the
INNER JOIN
, implicit when you specify onlyJOIN
, forLEFT OUTER JOIN
.– anonimo
To display "Vacant" if the field is NULL use:
COALESCE(ppref.nome, 'Vago') as Prefeito
, idem forpvice.nome
.– anonimo
How would it look to fit in this select a WHERE namePress = named ?
– Caique
But still bringing the same data in the same way, just adding a "filter"
– Caique