
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
Use MySQL CONCAT and LOWER Effectively
The contact() method is used to concatenate. However, lower() is used to change the case to lowercase. For our example, let us create a table.
The query to create a table is as follows
mysql> create table concatAndLowerDemo -> ( -> FirstValue varchar(10), -> SecondValue varchar(10), -> ThirdValue varchar(10), -> FourthValue varchar(10) -> ); Query OK, 0 rows affected (0.55 sec)
Now you can insert some records in the table using insert command.
The query is as follows
mysql> insert into concatAndLowerDemo values('John','12345','Java','MySQL'); Query OK, 1 row affected (0.21 sec) mysql> insert into concatAndLowerDemo values('Hi','12345','98764','MongoDB'); Query OK, 1 row affected (0.24 sec) mysql> insert into concatAndLowerDemo values('9485','746464','903940','cpp'); Query OK, 1 row affected (0.15 sec)
Display all records from the table using select statement.
The query is as follows
mysql> select *from concatAndLowerDemo;
The following is the output
+------------+-------------+------------+-------------+ | FirstValue | SecondValue | ThirdValue | FourthValue | +------------+-------------+------------+-------------+ | John | 12345 | Java | MySQL | | Hi | 12345 | 98764 | MongoDB | | 9485 | 746464 | 903940 | cpp | +------------+-------------+------------+-------------+ 3 rows in set (0.00 sec)
Here is the query to use concat() and lower() in the same query
mysql> select lower(concat(FirstValue,SecondValue,ThirdValue,FourthValue)) AS lowerDemo from concatAndLowerDemo;
The following is the output
+---------------------+ | lowerDemo | +---------------------+ | john12345javamysql | | hi1234598764mongodb | | 9485746464903940cpp | +---------------------+ 3 rows in set (0.00 sec)
Advertisements