I'm learning postgres windows functions and I'm having a little trouble converting this SQL query.
Right now, my query returns the first row in the result of the window function, I want to make it return the last row. I can't use a simple integer like I did with the "first result" because each result has a differing number of rows.
Here's the query:
select * from (select *, row_number() over (partition by user_id) as row_number from photos) as rows where row_number = 1 and deleted = false
I want to be able to specify row_number = last_row()
or something similar. Is that possible?
row_number()
without anorder by
does not really make sense. If you add that, just sortDESC
ending and take the row with row number = 1