Asked 3 years ago
21 Sep 2021
Views 738
Palma

Palma posted

MySQL CONCAT() Function

sandip

sandip
answered Sep 21 '21 00:00

MySQL CONCAT() is MySQL defined Function .
MySQL CONCAT() function is usefull to combine any number of strings in MySQL .
for example

select CONCAT('One ' , '1 ', "Two ", '2')

above select query with CONCAT will return one string combined of all passed strings.
so output

One 1 Two 2


so you can say syntax of the MySQL CONCAT() function is :

CONCAT(string1, string2,string3 .... ) 

here CONCAT function's parameters can be fieldnames or strings

for example three field firstname , middlename and lastname combined as full name by MySQL CONCAT() function:

select CONCAT(firstname," ",middlename," ",lastname) as name 

jignesh

jignesh
answered Sep 22 '21 00:00

Return type of MySQL CONCAT() is string.
MySQL CONCAT() also can be used to check multiple fields at the same time.
for example, if I want to show a record that has Select privilege=YES, Insert privilege=YES, Update privilege=YES then a normal query can be like this

SELECT * FROM `db` where  Select_priv='Y' and Insert_priv='Y' and Update_priv='Y'

but with CONCAT() function it can be easily like this

SELECT * FROM `db` where  CONCAT(Select_priv,Insert_priv,Update_priv)='YYY'

In the above query, we use CONCAT in the where condition we joined all conditions in one and it boosts speed and also easy to understand and look simple
Post Answer