If tutorials available on this website are helpful for you, please whitelist this website in your ad blocker😭 or Donate to help us ❤️ pay for the web hosting to keep the website running.
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)