
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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 Minimum and Maximum Value from Varchar Column in MySQL
Let us first create a table −
mysql> create table DemoTable ( Value varchar(100) ); Query OK, 0 rows affected (0.75 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('190'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('230'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('120'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('189'); Query OK, 1 row affected (0.19 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+-------+ | Value | +-------+ | 190 | | 230 | | 120 | | 189 | +-------+ 4 rows in set (0.00 sec)
Following is the query to get the minimum and maximum value from a VARCHAR column and display the result in separate MySQL columns −
mysql> select min(cast(Value AS SIGNED)) AS Min, max(cast(Value AS SIGNED)) AS Max from DemoTable;
This will produce the following output −
+------+------+ | Min | Max | +------+------+ | 120 | 230 | +------+------+ 1 row in set (0.03 sec)
Advertisements