I'm trying to adapt a query that works in MSSQL to Oracle, the query is much bigger (this part is just a field from a much bigger query) but I managed to reduce it so it looks simpler.
SELECT CASE WHEN COUNT(*) > 0 THEN COUNT(*)
ELSE (SELECT COUNT(*) FROM table2)
END
FROM table1
The error I'm getting is:
ora-00937 not a single-group group function
Can someone tell me where's the problem or how can I redefine it?
NikNik :
You can try with this query:\n\nSELECT CASE WHEN (SELECT COUNT(*) FROM table1) > 0 then (SELECT COUNT(*) FROM table1)\n ELSE (SELECT COUNT(*) FROM table2)\n END\nFROM dual;\n\n\nIt is still ugly but it works :)\n\nUpdate:\n\nTo explain how it's working:\n\nWe have 2 cases:\n\n\nIf there are records in the table1 then show me how many records\nthere are\nIf the table1 is empty, then give me the number of records from the\ntable2\n\n\nDual is the dummy table.",
2017-08-09T07:54:42