I have the following table:
create table weights (
ident int references users,
dateW date,
weight float,
primary key(ident,dateW)
);
I wanna select only the weight from a given user (ident) with the most recent date. I have:
SELECT WEIGHT
FROM WEIGHTS
WHERE WEIGHTS.IDENT = 22 AND WEIGHTS.DATEW = (SELECT MAX(WEIGHTS.DATEW)
FROM WEIGHTS);
But it’s not doing what I want. Suggestions?
You can use a subquery:
Or you can apply
row_number()