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:

pythonquery = "SELECT MAX(id) FROM users"

The result of the executed code:

python{'MIN(id)': 1}

Example

You can select both the maximum and minimum value of a field at the same time:

pythonquery = "SELECT MAX(id), MIN(id) FROM users"

The result of the executed code:

python{'MAX(id)': 6, 'MIN(id)': 1}

Practical tasks

Задание 1

Select the oldest user from the table.

Задание 2

Select the user with the highest salary.

Задание 3

Select users with minimum and maximum salaries.