
- 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
Implement GREATEST() in MySQL and update the table?
Let us first create a table −
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Number int ); Query OK, 0 rows affected (0.64 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable(Number) values(10); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable(Number) values(50); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable(Number) values(100); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable(Number) values(190); Query OK, 1 row affected (0.12 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+----+--------+ | Id | Number | +----+--------+ | 1 | 10 | | 2 | 50 | | 3 | 100 | | 4 | 190 | +----+--------+ 4 rows in set (0.00 sec)
Following is the query to update greatest() in MySQL −
mysql> update DemoTable set Number=GREATEST(200,Number) WHERE Id=3; Query OK, 1 row affected (0.16 sec) Rows matched: 1 Changed: 1 Warnings: 0
Let us display table records once again −
mysql> select *from DemoTable;
This will produce the following output −
+----+--------+ | Id | Number | +----+--------+ | 1 | 10 | | 2 | 50 | | 3 | 200 | | 4 | 190 | +----+--------+ 4 rows in set (0.00 sec)
- Related Articles
- Update table and order dates in MySQL
- Create a table in MySQL and implement TIMESTAMPDIFF()?
- Implement INSERT … ON DUPLICATE KEY UPDATE in MySQL
- INSERT INTO table if a table exists in MySQL else implement CREATE TABLE and create the table
- Update a MySQL table with Java MySQL
- Update table with duplicate ids in MySQL
- How to batch update MySQL table?
- How to select the table with the greatest number of columns in MySQL?
- How can we update any value in MySQL view as we can update the values in MySQL table?
- Can we perform MySQL UPDATE and change nothing in a table?
- Implement MySQL trigger in the first table to insert records in the second table?
- Update data in one table from data in another table in MySQL?
- How to update MySQL table storage engine
- How can we update the values in one MySQL table by using the values of another MySQL table?
- How can we update values in a MySQL table?

Advertisements