I have a Postgres table that looks like this:
id | a |
---|---|
1 | 1 |
2 | 1 |
3 | 2 |
4 | 3 |
5 | 3 |
6 | 4 |
7 | 4 |
I want to get rows that only have the biggest id
(primary key) where column a
values are different but all in a list of numbers, i.e. expected output for rows where a are 1 and 3:
id | a |
---|---|
2 | 1 |
5 | 3 |
How to write a SQL statement to fill this need?
SELECT *
FROM table
WHERE a IN (1, 3) ...
Any advice would be appreciated, thank you in advance!