Amine
Amine

Reputation: 367

Error in query ORA-00979: not a GROUP BY expression

I have a query that worked for me when I was using Mysql. Now I get this error on Oracle :

ORA-00979: not a GROUP BY expression

This is the query:

SELECT o.neNesId, COUNT(o) 
FROM ParNe AS o 
WHERE o.neBanId = :neBanId 
GROUP BY o.neNesId

Any ideas why I have this error?

Upvotes: 0

Views: 1085

Answers (3)

Art
Art

Reputation: 5782

You need to select count(*) or count(1) as in Gordon's example. If you insist on using your query syntax, which is not necessary at all then try this:

SELECT neNesId, count(o) AS o_cnt
  FROM
  (  -- your query here --
   SELECT 1 neNesId, 2 AS o FROM dual
  )
  GROUP BY neNesId
  /

Upvotes: 0

Biswajit
Biswajit

Reputation: 2506

use count(*) . count(o) is used in hibernate not in sql query

Upvotes: 0

Gordon Linoff
Gordon Linoff

Reputation: 1269543

Your query is:

SELECT o.neNesId, COUNT(o)
FROM ParNe AS o
WHERE o.neBanId = :neBanId
GROUP BY o.neNesId

My guess is that o.o is not a valid field. So, you have a table name where a column name is expected. Try this instead:

SELECT o.neNesId, COUNT(*)
FROM ParNe AS o
WHERE o.neBanId = :neBanId
GROUP BY o.neNesId

Or replace the * with a valid column name.

Upvotes: 2

Related Questions