Please help me to find the sqlite equivalent of the below query. Tried searching a lot.
SET @rownum := 0;
SELECT * FROM (
SELECT @rownum := @rownum+1 AS rank, id
FROM tbl_flight
ORDER BY id DESC
) AS tbl_flight WHERE id = 2
Please help me to find the sqlite equivalent of the below query. Tried searching a lot.
SET @rownum := 0;
SELECT * FROM (
SELECT @rownum := @rownum+1 AS rank, id
FROM tbl_flight
ORDER BY id DESC
) AS tbl_flight WHERE id = 2
You can't do this in a single query, but you can use temporary tables and the rowid property of every table:
http://sqlfiddle.com/#!5/f0a1b/8 (You can't run the fiddle twice, you have to always rebuild schema first before running it again)
DROP TABLE IF EXISTS tmp;
CREATE TEMPORARY TABLE tmp AS
SELECT id
FROM tbl_flight
ORDER BY id DESC;
SELECT tmp.rowid AS rank, tmp.id FROM tmp WHERE id=2;