Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Databases
  • SQL
  • MySQL
  • PostgreSQL
  • PL/SQL
  • MongoDB
  • SQL Cheat Sheet
  • SQL Interview Questions
  • MySQL Interview Questions
  • PL/SQL Interview Questions
  • Learn SQL and Database
Open In App
Next Article:
COT() Function in MySQL
Next article icon

CONCAT() function in MySQL

Last Updated : 07 Jun, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

CONCAT() function in MySQL is used to concatenating the given arguments. It may have one or more arguments. If all arguments are nonbinary strings, the result is a nonbinary string. If the arguments include any binary strings, the result is a binary string. If a numeric argument is given then it is converted to its equivalent nonbinary string form. Syntax :

CONCAT(str1, str2, ...)

Parameter : This method accepts N argument.  

  • str1, str2.str3…. : The input string which we want to concatenate.

Returns : It returns a new string after concatenating all input string. If any of the input string is NULL then it returns NULL. Example-1 : Concatenating 3 string using CONCAT Function.

SELECT CONCAT('geeks', 'for', 'geeks') AS ConcatenatedString ;

Output :

ConcatenatedString
geeksforgeeks

Example-2 : Concatenating numeric string using CONCAT Function.

SELECT CONCAT(19, 10, 5.60) AS ConcatenatedNumber ;

Output :

ConcatenatedNumber
19105.60

Example-3 : Concatenating string which includes a NULL String using CONCAT Function.

SELECT CONCAT('geeks', 'for', 'geeks', NULL) AS ConcatenatedString ;

Output :

ConcatenatedString
NULL

Example-4 : In this example we are going to concatenate string between column of a table. To demonstrate create a table named Student.

CREATE TABLE Student(  StudentId INT AUTO_INCREMENT,   FirstName VARCHAR(100) NOT NULL, LastName VARCHAR(100) NOT NULL, Class VARCHAR(20) NOT NULL, City VARCHAR(20) NOT NULL, State VARCHAR(20) NOT NULL, PinNo INT  NOT NULL, PRIMARY KEY(StudentId )  );

Now inserting some data to the Student table :

INSERT INTO   Student(FirstName, LastName, Class, City, State, PinNo ) VALUES ('Sayantan', 'Maity', 'X', 'Kolkata', 'WestBengal', 700001 ), ('Nitin', 'Shah', 'XI', 'Jalpaiguri', 'WestBengal', 735102 ), ('Aniket', 'Sharma', 'XI', 'Midnapore', 'WestBengal', 721211 ), ('Abdur', 'Ali', 'X', 'Malda', 'WestBengal', 732101 ), ('Sanjoy', 'Sharama', 'X', 'Kolkata', 'WestBengal', 700004 ) ;

So, the Student table is :

Select * From Student ;
StudentId FirstName LastName Class City State PinNo
1 Sayantan Maity X Kolkata WestBengal 700001
2 Nitin Shah XI Jalpaiguri WestBengal 735102
3 Aniket Sharma XI Midnapore WestBengal 721211
4 Abdur Ali X Malda WestBengal 732101
5 Sanjoy Sharama X Kolkata WestBengal 700004

Now, we will concatenate FirstName and LastName to get FullName and City, State and PinNo to get Address using CONCAT Function.

Select      StudentId, FirstName, LastName,      CONCAT(FirstName, ' ', LastName) AS FullName,     CONCAT(City, ' ', State, ' ', PinNO) AS Address      FROM Student;    

Output :

StudentId FirstName LastName FullName Address
1 Sayantan Maity Sayantan Maity Kolkata WestBengal 700001
2 Nitin Shah Nitin Shah Jalpaiguri WestBengal 735102
3 Aniket Sharma Aniket Sharma Midnapore WestBengal 721211
4 Abdur Ali Abdur Ali Malda WestBengal 732101
5 Sanjoy Sharama Sanjoy Sharama Kolkata WestBengal 700004


Next Article
COT() Function in MySQL
author
jana_sayantan
Improve
Article Tags :
  • SQL
  • DBMS-SQL
  • mysql

Similar Reads

  • COUNT() Function in MySQL
    The COUNT() function in MySQL is a versatile aggregate function used to determine the number of rows or non-NULL values that match a specific condition in a query. It can be applied to an entire table or a particular column and is widely used in database operations to analyze the volume of data in a
    3 min read
  • CONCAT_WS() Function in MySQL
    CONCAT_WS() : This function in MySQL helps in joining two or more strings along with a separator. The separator must be specified by the user and it can also be a string. If the separator is NULL, then the result will also be NULL. Syntax : CONCAT_WS(separator, string1, string2, ...) Parameters : se
    2 min read
  • COT() Function in MySQL
    COT() function : This function in MySQL is used to return the cotangent of a specified number. If the specified number is 0, an error or NULL will be returned. In a right triangle, the cotangent of an angle is the length of it's adjacent side divided by the length of the opposite side. Similarly, th
    1 min read
  • CURDATE() Function in MySQL
    The CURDATE() function in MYSQL is used to return the current date. The date is returned to the format of "YYYY-MM-DD" (string) or as YYYYMMDD (numeric). This function equals the CURRENT_DATE() function. In this article, we are going to discuss about CURDATE() function in detail. Syntax CURDATE(); P
    2 min read
  • MySQL | Group_CONCAT() Function
    The GROUP_CONCAT() function in MySQL is an aggregation function that combines data from multiple rows into a single string. It is particularly useful for aggregating summaries, such as combining related information into a single field for better readability or reporting. In this article, we will exp
    4 min read
  • BIT_COUNT() function in MySQL
    BIT_COUNT() function in MySQL is used to return the number of bits that are active in the given input. Active bits can be counted as a number of 1 presented in a binary number.Syntax : BIT_COUNT(number) Parameter : This method accepts only one parameter. number - Input integer whose number of active
    2 min read
  • MySQL | CONNECTION_ID( ) Function
    The MySQL CONNECTION_ID() function is used for return the connection ID for a current connection in MySQL. The connection ID used to establish a connection to a database is unique for every connection among the connected clients. The CONNECTION_ID() function does not require any parameters or argume
    1 min read
  • CRC32() Function in MySQL
    CRC32() function in MySQL is used to compute cyclic redundancy value. It returns NULL if the argument is NULL otherwise, it returns a 32-bit unsigned value after computing the redundancy. Syntax : CRC32(expr) Parameter : This method accepts only one parameter. expr -It is a string whose CRC32 value
    2 min read
  • DAY() Function in MySQL
    DAY() function : This function in MySQL is used to return the day of the month for a specified date (a number from 1 to 31). This function equals the DAYOFMONTH() function. Syntax : DAY(date) Parameter : This method accepts a parameter which is illustrated below : date : Specified date to extract th
    1 min read
  • ELT() Function in MySQL
    In this article, we are going to cover ELT function with examples. In ELT function, number field will state that how many strings will be there. ELT function in MySQL is used to returns the string which is at index number specified in the argument list. In this function there is number field and str
    1 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences