Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sqlite get ROWID

Tags:

sqlite

consider this simple table(tbl1):

A|first letter B|second letter C|third letter 

first column is letter and second column is desc

I can do this query without any problem:

select * from tbl1 where letter='B'      -->>second letter 

My question is: how I can get(retrieve) the ROWID of the result row?

like image 572
ayyob khademi Avatar asked Mar 22 '13 12:03

ayyob khademi


People also ask

How do I find the row ID in SQLite?

ROWID doesn't enumerate the rows, it gives you the row ID, which is an internal ID used by sqlite, but ROW_NUMBER() is a function that generates sequential numbers for every result set.

How do I find the last row ID in SQLite?

SQLite has a special SQL function – last_insert_rowid() – that returns the ID of the last row inserted into the database so getting the ID of a new row after performing a SQL insert just involves executing the last_insert_rowid() command.

Can we use Rowid as primary key?

You should not use ROWID as the primary key of a table. If you delete and reinsert a row with the Import and Export utilities, for example, then its rowid may change. If you delete a row, then Oracle may reassign its rowid to a new row inserted later.

Does Rowid change in SQLite?

From the official documentation: “Rowids can change at any time and without notice. If you need to depend on your rowid, make it an INTEGER PRIMARY KEY, then it is guaranteed not to change”.


1 Answers

SELECT rowid, * FROM tbl1 WHERE letter = 'B' 
like image 60
CL. Avatar answered Sep 21 '22 12:09

CL.