Fetching Max Value in SQL in Python
To select one maximum value from all records, the function MAX should be applied.
Example
Let's select the user with the maximum id:
query = "SELECT MAX(id) FROM users"
The result of the executed code:
{'MIN(id)': 1}
Example
You can select both the maximum and minimum value of a field at the same time:
query = "SELECT MAX(id), MIN(id) FROM users"
The result of the executed code:
{'MAX(id)': 6, 'MIN(id)': 1}
Practical tasks
Select the oldest user from the table.
Select the user with the highest salary.
Select users with minimum and maximum salaries.