
- 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
Select maximum of sum of two columns in MySQL
To select maximum of sum of two columns, use aggregate function MAX() along with subquery. Let us first create a table −
mysql> create table DemoTable1587 -> ( -> Value1 int, -> Value2 int -> ); Query OK, 0 rows affected (0.59 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1587 values(30,50); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1587 values(80,90); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1587 values(40,67); Query OK, 1 row affected (0.13 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1587;
This will produce the following output −
+--------+--------+ | Value1 | Value2 | +--------+--------+ | 30 | 50 | | 80 | 90 | | 40 | 67 | +--------+--------+ 3 rows in set (0.00 sec)
Here is the query to select maximum of sum of two columns −
mysql> select * from DemoTable1587 -> where Value1+Value2=( select max(Value1+Value2) from DemoTable1587);
This will produce the following output −
+--------+--------+ | Value1 | Value2 | +--------+--------+ | 80 | 90 | +--------+--------+ 1 row in set (0.03 sec)
- Related Articles
- Select distinct combinations from two columns in MySQL?
- Select distinct values from two columns in MySQL?
- MYSQL select DISTINCT values from two columns?
- SELECT not null column from two columns in MySQL?
- Select and add result of multiplying two columns from a table in MySQL?
- MySQL alias for SELECT * columns?
- Select all duplicate MySQL rows based on one or two columns?
- Maximum Sum of Products of Two Arrays in C++
- MySQL Select Rows where two columns do not have the same value?
- Maximum Sum of Products of Two Array in C++ Program
- How to select the maximum value of a column in MySQL?
- Get the sum of columns for duplicate records in MySQL
- How do I SELECT none of the rows and columns in MySQL?
- Maximum Sum of Two Non-Overlapping Subarrays in C++
- Find Sum of pair from two arrays with maximum sum in C++

Advertisements