Query for last values from column1 show all rows
I have an example table:
Column1 | Column2 | Column3
--------+---------+--------
1 Test1 1.1.2021
2 Test1 1.1.2020
1 Test2 2.1.2021
3 Test1 4.1.2021
2 Test2 5.1.2020
1 Test3 6.1.2021
I want to get:
Column1 | Column2 | Column3
--------+---------+--------
2 Test2 5.1.2020
3 Test1 4.1.2021
1 Test3 6.1.2021
Is there a way using the query language?
Such as:
SELECT *
FROM TABLE1,
ORDER BY Column4 ASC, DISTINCT Column1.
Solution 1:
If I understand correctly, you want the most recent row -- based on column3
for each value in column1
. If so, you can use a correlated subquery:
select t.*
from table1 as t
where t.column3 = (select max(t2.column3)
from table1 as t2
where t2.column1 = t.column1
);