Kevin López
Kevin López

Reputation: 107

Select last row to meet condition

I have a database and I want to output the VAL of a row that has a POSITION of 49 with the highest ID. I have this code but I'm not sure where to go from here.

SELECT ID, POSITION,
CASE WHEN POSITION = 49 THEN VAL END
FROM Log

Upvotes: 0

Views: 155

Answers (1)

RoMEoMusTDiE
RoMEoMusTDiE

Reputation: 4824

simplest solution would be

SQL-SERVER

SELECT top 1 val
FROM Log
where position = 49
order by id desc

MySQL

   SELECT val
    FROM Log
    where position = 49
    order by id desc
    limit 1

Upvotes: 2

Related Questions