问题描述
我想检索我的Sqlite3数据库的前100行:
connection = sqlite3.connect('aktua.db')
cursor = connection.cursor()
print('Actual \tCliente \tHistórica')
cursor.execute("SELECT * FROM Referencias WHERE r_aktua LIKE '%K'").fetchmany(size=100)
for row in cursor:
print('%s \t%s \t%s' % row)
cursor.close()
connection.close()
我的代码检索数据库的所有行(+4000)。
我已经阅读了和 。
怎么了?
1楼
使用此限制SQL选择:
"SELECT * FROM Referencias WHERE r_aktua LIKE '%K' LIMIT 100"
或将您的代码更改为:
rows = cursor.execute("SELECT * FROM Referencias WHERE r_aktua LIKE '%K'").fetchmany(size=100)
for row in rows:
print('%s \t%s \t%s' % row)