how to get rowNum like column in sqlite IPHONE

The fake rownum solution is clever, but I am afraid it doesn’t scale well (for complex query you have to join and count on each row the number of row before current row).

I would consider using create table tmp as select /*your query*/.
because in the case of a create as select operation the rowid created when inserting
the rows is exactly what would be the rownum (a counter). It is specified by the SQLite doc.

Once the initial query has been inserted, you only need to query the tmp table:

select rowid, /* your columns */ from tmp
order by rowid

Leave a Comment