A connector is employed when we have to use MySQL with other programming languages. The work of mysql-connector is to provide access to MySQL Driver to the the required language. Thus, it generates a connection between the programming language and MySQL Server.
Python-MySQL-Connector
This is a MySQL Connector that allows Python to access MySQL Driver and implement SQL queries in its programming facility. Here we will try implementing Limit clause on our Database and will study the output generated.
LIMIT Clause Of SQL
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.
Syntax:
SELECT * FROM tablename LIMIT limit; SELECT * FROM tablename LIMIT limit OFFSET offset;
The following programs will help you understand this better.
DATABASE IN USE:

Example 1: program to display only 2 records
import mysql.connector # Conencting to the database mydb = mysql.connector.connect( host ='localhost', database ='College', user ='root', ) cs = mydb.cursor() # STUDENT and STudent are # two different database statement ="SELECT * FROM STUDENT LIMIT 2" cs.execute(statement) result_set = cs.fetchall() for x in result_set: print(x) |
OUTPUT:

Example 2:program to start from the second record and display the first two records
import mysql.connector # Conencting to the database mydb = mysql.connector.connect( host ='localhost', database ='College', user ='root', ) cs = mydb.cursor() # STUDENT and STudent are # two different database statement ="SELECT * FROM STUDENT LIMIT 2 OFFSET 1" cs.execute(statement) result_set = cs.fetchall() for x in result_set: print(x) |
OUTPUT:

Recommended Posts:
- Python MySQL - Where Clause
- Python MySQL - Order By Clause
- Connect MySQL database using MySQL-Connector Python
- Python MongoDB - Limit Query
- Python | sympy.limit() method
- Python | Handling recursion limit
- Python MySQL - Join
- MySQL-Connector-Python module in Python
- Python MySQL - Insert into Table
- Python MySQL - Drop Table
- Python MySQL - Select Query
- Python: MySQL Create Table
- Python MySQL - Create Database
- Python MySQL - Update Query
- Python MySQL - Delete Query
- How to install MySQL connector package in Python?
- Create MySQL Database Login Page in Python using Tkinter
- PyQt5 - How to know maximum number of items limit in ComboBox
- PyQt5 - Setting limit to number of items in ComboBox
- Reusable piece of python functionality for wrapping arbitrary blocks of code : Python Context Managers
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

