
- 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
Get MAX() on column in two MySQL tables?
Use GREATEST() to find the maximum. Let us first create a table −
mysql> create table DemoTable1 ( Number int ); Query OK, 0 rows affected (0.52 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1 values(80); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable1 values(229); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1 values(575); Query OK, 1 row affected (0.24 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable1;
Output
+--------+ | Number | +--------+ | 80 | | 229 | | 575 | +--------+ 3 rows in set (0.00 sec)
Following is the query to create second table −
mysql> create table DemoTable2 ( Number int ); Query OK, 0 rows affected (0.51 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable2 values(485); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable2 values(10); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable2 values(475); Query OK, 1 row affected (0.12 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable2;
Output
+--------+ | Number | +--------+ | 485 | | 10 | | 475 | +--------+ 3 rows in set (0.00 sec)
Following is the query to get MAX() on column in two tables −
mysql> select greatest((select max(Number) from DemoTable1),(select max(Number) from DemoTable2));
Output
+-----------------------------------------------------------------------------------------+ | greatest((select max(Number) from DemoTable1),(select max(Number) from DemoTable2)) | +-----------------------------------------------------------------------------------------+ | 575 | +-----------------------------------------------------------------------------------------+ 1 row in set (0.00 sec)
- Related Questions & Answers
- Perform MySQL LEFT JOIN on two tables?
- How to get the max of two values MySQL?
- MySQL join two tables?
- A single MySQL select query on two tables is possible?
- Merge two tables with union in MySQL?
- How can you perform full join on two tables using MySQL in Python?
- How can you perform right join on two tables using MySQL in Python?
- How can you perform left join on two tables using MySQL in Python?
- How can you perform inner join on two tables using MySQL in Python?
- How can you perform self join on two tables using MySQL in Python?
- How to combine two tables and add a new column with records in MySQL?
- How to get the Average on MySQL time column?
- How can I merge two MySQL tables?
- Concatenate two tables in MySQL with a condition?
- Match column values on the basis of the other two column values in MySQL
Advertisements