SQLite Forum

Select distinct from most recent record
Login
I cannot figure out what you mean.

I'm *thinking* that you mean you want the "most recent" (as in highest number value in col2) item for every distinct value in col1, right?

If that is the case simply:

```
SELECT col, MAX(col2) FROM t GROUP BY Col1;
```

This will of course not always work if you are looking to select many columns from that row, and other caveats, but before I talk about any of that, let's first see if this is what was meant and needed.

When next asking a question, what really helps to alleviate any ambiguity, is to show us the intended results after the query ran successfully according to you.

```
Example: For these inputs/rows in my db:
col1,col2
AAA,58000
AAA,60000
AAA,62000
AAA,64000
AAA,66000
AAA,68000
AAA,70000
AAA,74000
AAA,76000
AAA,78000
BBB,72000
BBB,78000
BBB,86000
BBB,90000
BBB,98000
BBB,102000
BBB,110000
BBB,112000
BBB,114000
BBB,146000
BBB,150000
BBB,154000


I want the query to produce results like this:
col1,col2
AAA,78000
BBB,154000
```

or some such.