Python MySQL Limit


limit का use Database Table से limited records select करने के लिए किया जाता है।

# import connector class from mysql module.
import mysql.connector as myconn mydb = myconn.connect( host = 'localhost', user = 'root', password = '', database = 'python_db' ) db_cursor = mydb.cursor() # select only 2 records. query = "SELECT * FROM users LIMIT 2" db_cursor.execute(query) rows = db_cursor.fetchall() for row in rows : print(row)

Limit से आप सिर्फ records को select करने के limited records को update / delete भी कर सकते हैं।
For Example -

#delete 5 records.
query = "DELETE FROM users WHERE last_name=%s LIMIT 5" value = ('Singh', ) db_cursor.execute(query, value) #update only 3 records. query = "UPDATE users SET email = %s WHERE id=%s LIMIT 3" set_value = ('changedEmail@gmail.com', 1) db_cursor.execute(query, set_value)

Hey ! I'm Rahul founder of learnhindituts.com. Working in IT industry more than 4.5 years. I love to talk about programming as well as writing technical tutorials and blogs that can help to others .... keep learning :)

Get connected with me - LinkedIn Twitter Instagram Facebook