

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find the greatest value among four tables in MySQL?
To find the greatest value among four tables, you can use the method GREATEST(). Following is the query to create first table −
<DemoTable1>
mysql> create table DemoTable1 -> ( -> Value int -> ); Query OK, 0 rows affected (0.70 sec)
Insert some records in the first table using insert command −
mysql> insert into DemoTable1 values(10); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1 values(60); Query OK, 1 row affected (0.14 sec)
Display all records from the first table using select statement −
mysql> select *from DemoTable1;
Output
+-------+ | Value | +-------+ | 10 | | 60 | +-------+ 2 rows in set (0.00 sec)
Following is the query to create second table −
<DemoTable2>
mysql> create table DemoTable2 -> ( -> Value int -> ); Query OK, 0 rows affected (0.67 sec)
Insert some records in the second table using insert command −
mysql> insert into DemoTable2 values(90); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable2 values(12);; Query OK, 1 row affected (0.12 sec)
Display all records from the second table using select statement −
mysql> select *from DemoTable2;
Output
+-------+ | Value | +-------+ | 90 | | 12 | +-------+ 2 rows in set (0.00 sec)
Following is the query to create third table −
<DemoTable3>
mysql> create table DemoTable3 -> ( -> Value int -> ); Query OK, 0 rows affected (0.65 sec)
Insert some records in the third table using insert command −
mysql> insert into DemoTable3 values(34); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable3 values(120); Query OK, 1 row affected (0.17 sec)
Display all records from the third table using select statement −
mysql> select *from DemoTable3;
Output
+-------+ | Value | +-------+ | 34 | | 120 | +-------+ 2 rows in set (0.00 sec)
Following is the query to create fourth table −
<DemoTable4>
mysql> create table DemoTable4 -> ( -> Value int -> ); Query OK, 0 rows affected (0.68 sec)
Insert some records in the fourth table using insert command −
mysql> insert into DemoTable4 values(140); Query OK, 1 row affected (0.72 sec) mysql> insert into DemoTable4 values(290); Query OK, 1 row affected (0.14 sec)
Display all records from the fourth table using select statement −
mysql> select *from DemoTable4;
output
+-------+ | Value | +-------+ | 140 | | 290 | +-------+ 2 rows in set (0.00 sec)
Here is the query to find the greatest value among four tables in MySQL −
mysql> select greatest( -> (select max(Value) from DemoTable1), -> (select max(Value) from DemoTable2), -> (select max(Value) from DemoTable3), -> (select max(Value) from DemoTable4) -> ) as MaximumValue;
Output
+--------------+ | MaximumValue | +--------------+ | 290 | +--------------+ 1 row in set (0.00 sec)
- Related Questions & Answers
- C++ program to find greatest among four input integers
- A single MySQL query to find the highest and lowest among two tables?
- How to find missing value between two MySQL Tables?
- How do I select four random tables from a MySQL database having thousands of tables?
- MySQL Query to find tables modified in the last hour?
- Implement GREATEST() in MySQL and update the table?
- How to auto-increment value of tables to lower value in MySQL?
- Find minimum score from the entire four columns of a table in MySQL
- Find the greatest product of three numbers in JavaScript
- Get the highest score value from a single column and the greatest from two columns in MySQL
- How to find the distance among matrix values in R?
- Java Program to Find the Largest Among Three Numbers
- How can we see MySQL temporary tables in the list of tables?
- Write a Python program to find the maximum value from first four rows in a given series
- Find the Maximum Value in a Column in MySQL