< 1 min read
You can limit the number of records returned from the query, by using the “LIMIT” statement:
“LIMIT”-г ашиглан хүсэлтээс буцсан мөрүүдийн тоог хязгаарлаж болно.
Select the 5 first records in the “customers” table:
“customers” хүснэгтээс эхний 5 мөрийг сонгох:
import mysql.connectormydb = mysql.connector.connect( host="localhost", user="yourusername", password="yourpassword", database="mydatabase")mycursor = mydb.cursor()mycursor.execute("SELECT * FROM customers LIMIT 5")myresult = mycursor.fetchall()for x in myresult: print(x)
If you want to return five records, starting from the third record, you can use the “OFFSET” keyword:
Хэрвээ та 3 дах мөрнөөс эхэлж 5 мөрийг буцааж авахийг хүсвэл, “OFFSET” түлхүүр үгийг ашиглана:
Start from position 3, and return 5 records:
3 дах байршил дах мөрөөс эхэлж 5 мөрийг буцаа:
import mysql.connectormydb = mysql.connector.connect( host="localhost", user="yourusername", password="yourpassword", database="mydatabase")mycursor = mydb.cursor()mycursor.execute("SELECT * FROM customers LIMIT 5 OFFSET 2")myresult = mycursor.fetchall()for x in myresult: print(x)
Powered by BetterDocs
You must be logged in to post a comment.