Answer the question
In order to leave comments, you need to log in
How to get latest sqlite records?
How to get records in reverse order sqlite? An important clarification, there is no id or similar sorting options. https://zametkinapolyah.ru/zametki-o-mysql/chast-1... this guide is not suitable in my case.
There is a code:
import sqlite3
db = sqlite3.connect('database.db', check_same_thread = False)
cursor = db.cursor()
cursor.execute('''CREATE TABLE IF NOT EXISTS test (
id BIGINT,
call TEXT
)''')
t = 10
for i in range(10):
cursor.execute(f"INSERT INTO test VALUES (?, ?)", (i, t-1))
db.commit()
check = cursor.execute(f'SELECT * FROM test')
search = check.fetchall()
print(search)
[(0, 10), (1, 9), (2, 8), (3, 7), (4, 6), (5, 5), (6, 4), (7, 3), (8, 2), (9, 1)]
Answer the question
In order to leave comments, you need to log in
sql databases, in the standard, do not guarantee the order of the results in a query if order by is not specified (an exception, group by, you need to read the documentation for each database used and the use of specific indexes).
The fact that if it works as you expect in 1000 cases, in 1001 you will get an unexpected result (a lot of situations, unsuccessful combinations of adding and deleting records, a strange combination of records in the index, etc.)
in sqlite in each table, if specially don't remove it on creation, there is a rowid column which is the id of the entry, and it's a positive number, and it increments when added (reset by vacuum), maybe you have enough, sort by it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question