
- 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
Getting maximum from a column value and set it for all other values in the same column with MySQL?
Let us first create a table −
mysql> create table DemoTable ( FirstName varchar(100), Score int ); Query OK, 0 rows affected (0.60 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('David',59); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('Chris',97); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable values('Bob',98); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Carol',91); Query OK, 1 row affected (0.11 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+-----------+-------+ | FirstName | Score | +-----------+-------+ | David | 59 | | Chris | 97 | | Bob | 98 | | Carol | 91 | +-----------+-------+ 4 rows in set (0.00 sec)
Following is the query to get maximum from a column value and set it for all other values in the same column −
mysql> select FirstName,(select max(Score) from DemoTable) as Score from DemoTable;
This will produce the following output −
+-----------+-------+ | FirstName | Score | +-----------+-------+ | David | 98 | | Chris | 98 | | Bob | 98 | | Carol | 98 | +-----------+-------+ 4 rows in set (0.00 sec)
- Related Articles
- How to subtract the same amount from all values in a column with MySQL?
- How to update a column with the same values (not all) using UPDATE, SET and LIMIT in MySQL?
- Set a specific value for the first three column values in MySQL?
- Fetch the maximum value from a MySQL column?
- MySQL query to display record with maximum count values in a group with other column values?
- Select minimum row value from a column with corresponding duplicate column values in MySQL
- Set ENUM in MySQL for column values
- MySQL query to fetch the maximum corresponding value from duplicate column values
- Find maximum value from a VARCHAR column in MySQL
- Concatenate two values from the same column with different conditions in MySQL
- How to set all values in a single column MySQL Query?
- Two ways to fetch maximum value from a MySQL column with numbers
- MySQL query to set current date in the datetime field for all the column values
- Fetch the first letter of a column value and insert it in another column with MySQL
- Return value from a row if it is NOT NULL, else return the other row value in another column with MySQL

Advertisements