Skip to content
Advertisement

Get max date based on another column in SQL

I have a table variable which consists of columns id, date and status as shown below

And follows is the sample data

Also declared a variable as shown below.

From this table I need to get the row which containing the maximum value of date( MAX(dates) ) where status is ‘ABC’, from the above sample values, I should get the 3rd row as the result and I need to assign the corresponding id value of the row id to a variable (@MaxID).

I tried following queries but getting multiple result set

I need something like:

Please help.

Advertisement

Answer

Is this what you want?

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement