Fetchall() is excluding one row which is stored in fetchrow()

94 Views Asked by At

I am trying to create a code where i would get all the rows from the existing table if the condition matches otherwise return "Record is not there". Below fetchall() excludes one row which is sitting in fetchone() function. As i am new to this, i am not sure what is going wrong.

cursor = conn.cursor()

result=cursor.execute("SELECT * from Documents where documentID like '1167%')

row= cursor.fetchone()

if row is None:     
     print('Record is not there')

else:

     row=cursor.fetchall()
     print(row)
1

There are 1 best solutions below

1
l -_- l On

I suggest you reassemble your rows in a list using the * :

cursor = conn.cursor()
result = cursor.execute("SELECT * from Documents where documentID like '1167%'")
row = cursor.fetchone()

if row is None:     
     print('Record is not there')
else:
     other_rows=cursor.fetchall()
     rows = [row, *other_rows]
     print(rows)