
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
MySQL query to get the highest value from a single row with multiple columnsnnnnnnnnnn
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;
Output
+--------+--------+--------+ | 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;
Output
+-----------------+ | HighestFrom1Row | +-----------------+ | 600 | +-----------------+ 1 row in set (0.00 sec)
- Related Articles
- Comparing two columns in a single MySQL query to get one row?
- 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?
- Concatenate multiple rows and columns in a single row with MySQL
- MySQL query to sort multiple columns together in a single query
- Get the minimum value from a list with multiple columns in MySQL?
- Change multiple columns in a single MySQL query?
- Get only a single value from a specific MySQL row?
- How to sort multiple columns with a single query?\n
- How to get the fourth highest value using MySQL query?
- How to get multiple rows in a single MySQL query?
- How can I get the output of multiple MySQL tables from a single query?
- Update two columns with a single MySQL query
- How to check multiple columns for a single value in MySQL?

Advertisements