Caleb Klose Caleb Klose - 1 month ago 14
SQL Question

ERROR Message: ORA-00923: FROM keyword not found where expected

so i'm currently working with an oracle query that i want to grab the maximum sighting_distance along with its corresponding sighting_id value, however i keep running into the ORA-00923: FROM keyword not found where expected error. Any ideas how to fix this error?

SELECT TOP 1 SIGHTING_ID, sqrt(((-28 - LATITUDE)*(-28 - LATITUDE)) + ((151 - LONGITUDE)*(151 - LONGITUDE))) AS "SIGHTING_DISTANCE"
FROM(
SELECT SIGHTING_ID, longitude, latitude
FROM SIGHTINGS)
GROUP BY SIGHTING_DISTANCE
ORDER BY ASC;

Answer

SELECT TOP 1 does not exist in Oracle SQL. Select everything in a subquery, order the subquery, and then select everything again "where ROWMUM = 1". (There are many other ways to do this - if you have Oracle 12 there is a new feature very similar to "TOP 1".)

Comments