Prerequisite: Python: MySQL Create Table
In this article, we are going to see how to get the Minimum and Maximum Value of a Column of a MySQL Table Using Python. Python allows the integration of a wide range of database servers with applications. A database interface is required to access a database from Python. MySQL Connector-Python module is an API in python for communicating with a MySQL database.
Database in use:
We are going to use geeks(Database name) database and table describing the salary.
- Import module.
- Make a connection request with the database.
- Create an object for the database cursor.
- Execute the following MySQL query:
SELECT MIN(Column_name) AS minimum FROM Table_name. SELECT MAX(Column_name) AS minimum FROM Table_name.
- And print the result.
Example 1: Getting the minimum value of a column.
Example 2: Getting the maximum value of a column.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.