CancelImage Upload

Establishing a MySQL table's smallest and largest values using MIN and MAX

Establishing the smallest or largest field number within a table in MySQL requires the use of MIN() or MAX(). Within the brackets you can define the field you wish to find the largest or smallest values of. Here then is how we would find the winner and loser from a table called sportResults:

SELECT MAX(score) FROM sportResults

or

SELECT MIN(score) FROM sportResults

Of course we can also take things a step further. Let us say for instance the table sportResults also had a field called game within it. In that case we could find the winner and losers of various games by adding GROUP BY:

SELECT MAX(score), sportResults.game FROM sportResults GROUP BY game

or

SELECT MIN(score), sportResults.game FROM sportResults GROUP BY game


Login
Want to leave a comment?

No problem. Just enter your email and password below.


register | home | reminder

myDesignTool Networking • www.mydesigntool.cominfo@mydesigntool.com