Q:

How to find max value and the associated field in sql?

I am trying to select the highest ID and its description from a table using the following code. However it keeps returning null. Please could someone suggest where i am going wrong 
Select  ID, Description
FROM STOPS
where Description = (select MAX(ID) 
from STOPS);

A:

Use order by and the equivalent of fetch first 1 row only:
select s.*
from stops s
order by s.id desc
fetch first 1 row only;

This is ANSI-standard syntax.  Not all databases support fetch first, some use limit, select top, or rownum.

