Reputation: 13
I am currently trying to pull all measurements from a specific user in my database where the row has the maximum measurement ID (AKA their latest measurements)
What I have so far:
SELECT *
FROM Measurements
WHERE Measure_ID = (SELECT max(Measure_ID) FROM Measurements) AND Client_ID = 1
However, all it pulls is the column names and not the actual data. This SQL statement works with every other table I am using and I have no idea why it won't work for my measurements table. I even re-created the table and it still doesn't work. I have copied word for word from other statements that are working and changed the variables to fit this statement. Still nothing. Is there something I am missing?
Any help is appreciated!
Upvotes: 1
Views: 67
Reputation: 1269563
Just use order by
:
select top (1) m.*
from measurements m
where m.client_id = 1
order by m.Measure_ID desc;
Upvotes: 3