I am trying to apply a definition query to an AVL table (on an enterprise geodatabase - Microsoft SQL Server 2016) that returns the most recent record for each vehicle in the table. After a little research, I decided to use the TOP method which requires an ORDER BY statement. I've also included every field in the GROUP BY statement so that they can be included in the resulting table (per an error that I encountered).
Current SQL Query:
SELECT TOP(1) * FROM County.GIS.AVL_PW WHERE VGROUP <> 'Engineering' AND VGROUP <> 'Resource Mgt' GROUP BY VEHID ORDER BY ID ASC
The root of the issue is this: even when I remove "TOP(1)" from the SELECT statement, the resulting table is empty. This indicates, to me, that there is an non-syntax error somewhere else in the statement that I am unable to identify.
The error mentioned above can be ignored as after testing the code again, the error was not flagged a second time. Originally, the error stated that I could not include fields in the SELECT statement that were not also included in an aggregate function or a GROUP BY statement.