Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
665 views
in Technique[技术] by (71.8m points)

objective c - how to get rowNum like column in sqlite IPHONE

I have an Sqlite database table like this (with out ascending)

enter image description here

But i need to retrive the table in Ascending order by name, when i set it ascending order the rowId changes as follows in jumbled order

enter image description here

But i need to retrieve some limited number of contacts 5 in ascending order every time

like Aaa - Eeee and then Ffff- Jjjjj ......

but to se**t limits like 0-5 5-10 .... ** it can able using rowids since they are in jumble order

So i need another column like (rowNum in oracle) wich is in order 1234567... every time as follows

enter image description here

how to retrive that column with existing columns

Note: WE DONTE HAVE ROWNUM LIKE COLUMN IN SQLITE

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...