Devanshu Sharma
Devanshu Sharma

Reputation: 43

Set Limit On cursor Object before execute query in python

I have one query which I ran on mysql, mssql or oracle like

select * from user

that query give me 0.5 million records/rows. I want to get only 10 rows. Below is python code :

 cursor.execute(query)
 columns = cursor.description
 rows = cursor.fetchall()

I tried using cursor.fetchmany(10) and that condition is giving me 10 row but it takes a lot of time. I want to set a limit before executing the query so that it will be not take much time and also got fast execution. Please give me any solution in python. Please help me...

Upvotes: 2

Views: 2136

Answers (1)

methane
methane

Reputation: 479

When you only need 10 rows, use select * from user LIMIT 10.

Upvotes: 1

Related Questions