liveBook · Manning

Concatenation

As explained in Learn SQL in a Month of Lunches

CONCAT is an SQL string function that concatenates multiple values into a single string.

Concatenation combines two or more string values into one value. It solves a common reporting task: joining pieces such as a first name and last name or a title and review message. section 15.1

Join first and last names

SELECT CONCAT(FirstName, ' ', LastName) AS AuthorName FROM author; CONCAT receives comma-separated values. The space is included as its own value, so the two column values appear as one readable name. section 15.1.1

Do not assume that the plus sign joins strings. In MySQL, adding string values can produce 0 because the expression is treated as a mathematical calculation. SQL Server supports plus for strings, but the approach is not portable across most relational database systems. section 15.1

CONCAT also supports nearby reporting tasks:

  • Combine a title with a reusable message, such as a title name followed by “is a great book!”. section 15.1.1
  • Combine numeric or date values with strings, remembering that CONCAT converts every value to a string. section 15.1.1
  • Sort by the original numeric column when concatenated output must retain numeric ordering; sorting the combined text can place 10.95 before 7, 8, or 9. section 15.1.1
SELECT CONCAT(FirstName, ' ', LastName) AS AuthorName
FROM author;

Inspect a complete CONCAT query that turns FirstName and LastName columns into one AuthorName value. section 15.1.1

How Learn SQL in a Month of Lunches covers it

How deep it goes
Explains comma-separated arguments, mixed-type conversion, and sorting consequences, but does not cover implementation internals.
Examples
Demonstrates phrases, title reviews, price-and-title output, and author names using literals, variables, and table columns.
What you can do after
Apply it via CONCAT to create readable combined values and preserve numeric ordering with ORDER BY on the original column.
How it connects
Connects string concatenation with SQL expressions, data types, variables, table columns, and ORDER BY.

Also explained in

Compare how 10 books explain concatenation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn SQL in a Month of Lunches. The section links point to the parts of the book it draws on.