sudosudo
sudosudo

Reputation: 41

Sqlite DISTINCT inconsistant results

I am getting very different results just by adding a DISTINCT that shouldn't do anything.

My table has ~10000 rows with unique rowids.

However, when I run:

SELECT DISTINCT * FROM thetable GROUP BY rowid

I only get ~6000 of the rows. What?? Shouldn't every row be distinct since every row has a different row id?

Upvotes: 1

Views: 31

Answers (1)

sudosudo
sudosudo

Reputation: 41

Ahhh - rowid isn't automatically included in the returned rows so a row that is otherwise the same will be marked as duplicate.

The following fix works:

SELECT DISTINCT rowid, * FROM thetable GROUP BY rowid

Upvotes: 3

Related Questions