0
The query is summarized to facilitate:
SELECT
nome,idade,profissao,cidade, bairro, estado, pais
FROM objeto
group by nome,idade,profissao,cidade, bairro, estado, pais;
However 3 columns can come null
(profissao
, bairro
, estado
). When one of these columns comes null
, the column null
should not be used in the grouping of records, should group by which are not null
.
That is to say, (profissao
, bairro
, estado
) may be null or not, but need to be grouped by them when they come not null
.
can’t use a
where
to filter?– Ricardo Pontual
Here’s the deal. There’s no crying. If you don’t want to group by null, then you can’t come null in these columns, simple as that. Otherwise it will group by null. Add in your WHERE the clauses AND Nomecoluna IS NOT NULL and be happy. If I could do any tricks, it would be at HAVING of GROUP BY, but I believe that I can not.
– Piovezan
I get it. But if I put the " WHERE clauses AND IS NOT NULL Column", it will not bring the records that have some null column, and I need them. For example, one of the columns is of value, and I would need it grouped if the other columns that are not null are equal
– Rodrigo Jesus
Try something like nvl(column,'no information') in grouping.
– Motta
By this your example will
SELECT DISTINCT nome,idade,profissao,cidade, bairro, estado, pais FROM objeto
would not answer? It may be that its simplification has hindered the understanding.– anonimo
pq a group by se has no aggregation function ?
– Rovann Linhalis
agree with @Rovannlinhalis if select does not use aggregation there is no need for group by... if using to eliminate duplicates use the suggestion from
DISTINCT
above which is the correct way to do this– JMSlasher