Suppose you have a database with just one column i.e. ID
. If you want to select the latest 4 values entered in the DB file how would you do this? (I am using SQLite3
)
What i did to get the latest 1 value from the DB :
cur.execute("SELECT id FROM classes")
for class_Names in cur.fetchall():
pass
print(class_Names)
This returns me the latest value. What will i have to do to obtain latest 4 data from a database. What i tried as suggested by @Zaven Zareyan:
import sqlite3
conn = sqlite3.connect(r'C:\Users\intel\Desktop\Crawl_jar\test.db')
cur = conn.cursor()
cur.execute("SELECT * FROM classes ORDER BY id DESC LIMIT 4")
for class_Names in cur.fetchall():
print(class_Names)
But it results in:
('tVe95H',)
('tVe95H',)
('tVe95H',)
('sng_c explicticon',)
Original table:
('_3wU53n',)
('_3wU53n',)
('_3wU53n',)
('_3wU53n',)
('_3wU53n',)
('_3wU53n',)
('_3wU53n',)
('_3wU53n',)
('_2yAnYN',)
('_2ISNhP _3AOFWO',)
('puxlXr',)
('_1Nyybr _30XEf0',)
('_1Nyybr _30XEf0',)
('iUmrbN',)
('_1Nyybr _30XEf0',)
('_3BTv9X',)
('_1Nyybr _30XEf0',)
('_3BTv9X',)
('_1xHtJz',)
('_3wU53n',)
('_1Nyybr _30XEf0',)
('_1Nyybr _30XEf0',)
('_1Nyybr _30XEf0',)
('_1Nyybr _30XEf0',)
('_1UoZlX',)
('_1p7h2j',)
('LM6RPg',)
('_3Wn9Gb',)
('_1Nyybr _30XEf0',)
('_3wU53n',)
('tVe95H',)
('tVe95H',)
('_3wU53n',)
('_3wU53n',)
('tVe95H',)
('_1Nyybr _30XEf0',)
('sng_c explicticon',)
('sng_c explicticon',)
('sng_c',)
('ellipsis-single ware-brand',)
('ellipsis-single ware-brand',)
('question-hyperlink',)
('question-hyperlink',)
('question-hyperlink',)
('excerpt',)