- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Is there a MAX function for rows and not for columns in MySQL?
Yes, you can use GREATEST() from MySQL to check maximum from rows (not columns). Let us first create a table −
mysql> create table DemoTable ( Value1 int, Value2 int, Value3 int ); Query OK, 0 rows affected (0.58 sec)
Insert records in the table using insert command −
mysql> insert into DemoTable values(190,395,322); Query OK, 1 row affected (0.16 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output−
+--------+--------+--------+ | Value1 | Value2 | Value3 | +--------+--------+--------+ | 190 | 395 | 322 | +--------+--------+--------+ 1 row in set (0.00 sec)
Here is the query to get the MAX for rows (not columns)−
mysql> select greatest(Value1,Value2,Value3) as GreaterValue from DemoTable;
This will produce the following output −
+--------------+ | GreaterValue | +--------------+ | 395 | +--------------+ 1 row in set (0.04 sec)
Advertisements