SQLite Forum

how DISTINCT remove the duplicate rows?
Login
Yes.  Example:

```
sqlite> CREATE TABLE tab(c);
sqlite> create index ix on tab(c, typeof(c) desc);
sqlite> insert into tab values (1),(1.0);
sqlite> .eqp full
sqlite> SELECT DISTINCT c FROM tab;
QUERY PLAN
`--SCAN tab USING COVERING INDEX ix (~1048576 rows)
addr  opcode         p1    p2    p3    p4             p5  comment
----  -------------  ----  ----  ----  -------------  --  -------------
0     Init           0     16    0                    0   Start at 16
1     Null           1     2     0                    8   r[2]=NULL
2     OpenRead       2     3     0     k(3,,-,)       0   root=3 iDb=0; ix
3     ColumnsUsed    2     0     0     1              0
4     Explain        4     0     0     SCAN tab USING COVERING INDEX ix (~1048576 rows)  0
5     Noop           0     0     0                    0   Begin WHERE-loop0: tab
6     Rewind         2     14    1     0              0
7       Noop           0     0     0                    0   Begin WHERE-core
8       Column         2     0     1                    0   r[1]=tab.c
9       Eq             1     13    2     BINARY-8       128  if r[2]==r[1] goto 13
10      Copy           1     2     0                    0   r[2]=r[1]
11      ResultRow      1     1     0                    0   output=r[1]
12      Noop           0     0     0                    0   End WHERE-core
13    Next           2     7     0                    1
14    Noop           0     0     0                    0   End WHERE-loop0: tab
15    Halt           0     0     0                    0
16    Transaction    0     0     2     0              1   usesStmtJournal=0
17    Goto           0     1     0                    0
┌─────┐
│  c  │
├─────┤
│ 1.0 │
└─────┘
```

Note that in this case the solution is slightly different.  The table is traversed using the index and output rows that are duplicates of the preceding row are suppressed (since it is known that the results will be in order).  THe index causes the value 1.0 (type REAL) to be processed before value 1 (type integer) because the word "real" sorts before the word "integer" (in descending order).