I'm trying to create a query that returns the name and country of one thing that is in another table the largest number of times.
Here's the structure:
ShipModels(mname, type, country, numGuns, gunSize)
Ships(sname, hasModel, launchYear)
Battles(bname, year)
Outcomes(ship, battle, result)
I've tried many different things, but can't get it to work. This is my current query:
SELECT ship, country
FROM ShipModels, Ships, Outcomes
WHERE hasModel = mname AND ship = sname
GROUP BY ship
HAVING COUNT(ship) >=
( SELECT COUNT (ship) FROM Outcomes GROUP BY ship);
The Oracle error:
ERROR at line 1:
ORA-00979: not a GROUP BY expression
From what I have read, this error is thrown when there is an aggregate function in the SELECT statement, but...well, there isn't. Is there something I'm missing? How can I get this to work?