⊗pyPmDBMaVS 116 of 128 menu

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.

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline