0

I had that question in a code interview, I found a possible solution but I want to hear from you so thanks for your comments and help.

Select max(ID) from table where ID not in (select max(ID) from table)

1 Answers1

0

Use a window function:

select *
from (
   select x.*, 
          row_number() over (order by x.id) as rn
   from the_table x
) t
where rn = 2;