Suppose I have a table with column position
and 10 rows with values:
[1, 2, 3, 1, 1, 1, 2, 4, 3, 2].
How do I select * from that table with only 1 row for each position?
I use Postgresql, and If I use limit 1 it returns only 1 value (obviously) and I need 1 value of each position with order by create_date field.
2
Answers
You can do it using DISTINCT Keyword.
This will select one row per unique value in the
position
column with the most recentcreate_date
It can be done using GROUP BY of
position
Column and then ORDER BY ofposition
andcreate_date
.