-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path09_Limit_clause.py
More file actions
29 lines (21 loc) · 883 Bytes
/
09_Limit_clause.py
File metadata and controls
29 lines (21 loc) · 883 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
""" Limit Clause -> The Limit clause is used in SQL to control or limit the number of records in the result set returned from the query generated.
By default, SQL gives out the required number of records starting from the top but it allows the use of OFFSET keyword. OFFSET allows you to start from a custom row and get the required number of result rows."""
# Example: Limit clause in MySQL using Python
import mysql.connector
# Connect to the studentdb database
dataBase = mysql.connector.connect(
host ="localhost",
user ="root",
passwd ="Akhil@0109",
database = "studentdb"
)
# Create a cursor object
cursorObject = dataBase.cursor()
query = "SELECT * FROM students LIMIT 3 OFFSET 2"
cursorObject.execute(query)
myresult = cursorObject.fetchall()
print("🎓 Student Records:")
for x in myresult:
print(x)
# disconnecting from server
dataBase.close()