I am new to Python and I recently stuck in getting value from Sqlite. What I want is getting value only in second row of the table. This is the table data picture. And I have tried this but not working:
con = sqlite3.connect(database=r'ims.db')
cur = con.cursor()
for l in range(1,8):
cur.execute(f"Select occolor{l} from ordercart limit 2")
row = cur.fetchall()
print(row)
This will bring both first and second row value. But what I want are only the second row value. Anyone help with this pls?
>Solution :
fetchall returns a reference to a list. Your query will return at most 2 rows. Therefore:
if (row := cur.fetchall()):
print(row[-1])
else:
print('Not found')
Doing it like this allows for the results being either empty or containing just one row