How can CONCAT() function be used with MySQL WHERE clause?


Suppose from the table ‘Student’ we want to concatenate the values of columns, ‘Name’, ‘Address’ and ‘Columns’, based on the condition that is also a concatenation of values from columns, ’Name’, ‘Subject’, provided in WHERE clause with the help of CONCAT() function. We can use the following query to give the output −

mysql> Select CONCAT(Name, ' ', 'Resident of', ' ', Address,' ','is',' ', 'Studying',' ', Subject)AS 'Detail of Student' from Student WHERE CONCAT(Name, Subject) = "AaravHistory";
+----------------------------------------------+
| Detail of Student                            |
+----------------------------------------------+
| Aarav Resident of Mumbai is Studying History |
+----------------------------------------------+
1 row in set (0.00 sec)

Updated on: 30-Jan-2020

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements