Name
CONCAT( )
Synopsis
CONCAT(string
, . . . )
With this function, strings of text and strings from columns can be concatenated or pasted together under one resulting column. If any of the strings are NULL, a NULL value is returned for the selected row.
SELECT CONCAT(name_first, ' ', name_last) AS Student FROM students WHERE name_last = 'Dyer'; +-------------------+ | Student | +-------------------+ | Kenneth Dyer | | Geoffrey Dyer | | Marie Dyer | | NULL | +-------------------+
In this example, the database contained four students with the last name Dyer, but for one of them there was a NULL value in the name_first column. Within the parentheses of the function, notice that a space is given within quotes as the second element so that the display shows a space between each student’s first and last name.
Get MySQL in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.