- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
MySQL query to get the highest value from a single row with multiple columns
To get the highest value, use the GREATEST() method. Let us first create a table −
mysql> create table DemoTable -> ( -> Value1 int, -> Value2 int, -> Value3 int -> ); Query OK, 0 rows affected (1.29 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(100,600,400); Query OK, 1 row affected (0.19 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
+--------+--------+--------+ | Value1 | Value2 | Value3 | +--------+--------+--------+ | 100 | 600 | 400 | +--------+--------+--------+ 1 row in set (0.00 sec)
Following is the query to get the highest value −
mysql> select greatest(Value1,Value2,Value3) AS HighestFrom1Row from DemoTable;
+-----------------+ | HighestFrom1Row | +-----------------+ | 600 | +-----------------+ 1 row in set (0.00 sec)
- Get the highest score value from a single column and the greatest from two columns in MySQL
- Update multiple columns of a single row MySQL?
- Can we update a row with the highest ID in a single MySQL query?
- Comparing two columns in a single MySQL query to get one row?
- Get the minimum value from a list with multiple columns in MySQL?
- Change multiple columns in a single MySQL query?
- Concatenate multiple rows and columns in a single row with MySQL
- Get only a single value from a specific MySQL row?
- MySQL query to sort multiple columns together in a single query
- How to sort multiple columns with a single query?
- How to get the fourth highest value using MySQL query?
- How to get multiple rows in a single MySQL query?
- Update two columns with a single MySQL query
- How to check multiple columns for a single value in MySQL?
- How can I get the output of multiple MySQL tables from a single query?