Skip to content
Advertisement

Why I’m getting ORA-00979 while trying to use LISTAGG and LEFT JOIN?

I’m trying to group my results so, instead of looking like this:

It looks like this:

The ‘id’ and ‘nome’ are in table 1 and ‘bairro’ is in table 3 in the column ‘nome’.

table 1

table 2

table 3

I’m trying to do it using LISTAGG with the code below:

When I do it, I get the error

ORA-00979: not a group by expression

Can someone help me? I’m a beginner

edit: Already tried adding table1.nome to my group by.

Advertisement

Answer

I think it’s because you’re using an aggregating function which returns a single row, alongside columns which will return multiple rows. So you either need to group every “normal” column in your GROUP BY clause, or apply some aggregating function to the values from the “normal” columns, such as MIN, MAX, SUM, etc.

In your example, it would be something like

or

There is an alternative, which is to use the

clause, e.g. something like

See the Oracle docs for some examples.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement