You can find the highest number in a column with the help of aggregate function MAX. The syntax is as follows −
select max(yourColumnName) as anyVariableName from yourTableName;
To understand the above concept, let us create a table with an int column. The following is the query to create a table.
mysql> create table HighestNumberDemo −> ( −> BigNumber int −> ); Query OK, 0 rows affected (0.87 sec)
Now insert some values in the table. The query to insert records are as follows −
mysql> insert into HighestNumberDemo values(1234); Query OK, 1 row affected (0.43 sec) mysql> insert into HighestNumberDemo values(9999); Query OK, 1 row affected (0.18 sec) mysql> insert into HighestNumberDemo values(10000); Query OK, 1 row affected (0.17 sec) mysql> insert into HighestNumberDemo values(989898); Query OK, 1 row affected (0.14 sec) mysql> insert into HighestNumberDemo values(999987); Query OK, 1 row affected (0.18 sec)
Now you can display all records with the help of select statement. The query to display all records are as follows −
mysql> select *from HighestNumberDemo;
The following is the output −
+-----------+ | BigNumber | +-----------+ | 1234 | | 9999 | | 10000 | | 989898 | | 999987 | +-----------+ 5 rows in set (0.00 sec)
Implement the syntax we discussed above to find the highest number in a column. The query is as follows −
mysql> select max(BigNumber) as HighestNumber from HighestNumberDemo;
The following is the output −
+---------------+ | HighestNumber | +---------------+ | 999987 | +---------------+ 1 row in set (0.00 sec)