CONCAT() Function SQL (+)

To connect multiple strings together is called "concatenation". To do this in mySQL the CONCAT() function is employed with the various strings to be combined as its parameters. For example:

SELECT CONCAT(book,', by ', author) AS bna FROM fict_chars

We apply this to our female fictional characters table, "fict_chars".

fem_idnamebookauthor
1Scarlet O'HaraGone With the WindMargaret Mitchell
2Hermione GrangerHarry PotterJ.K. Rowling
3Jane PorterTarzanE.R. Burroughs

The result:

bna
Gone With the Wind, by Margaret Mitchell
Harry Potter, by J.K. Rowling
Tarzan, by E.R. Burroughs

In other applications of SQL the + operator may be used to the same effect. Our example above would look like:

SELECT (book + ,', by ', + author) AS bna FROM fict_chars

The CONCAT_WS() function is a special form of the CONCAT() function. The WS stands for "with separator". The syntax:

SELECT CONCAT_WS('separator', 'string' or column, 'string' or column, etc.)

It will concatenate strings with a designated symbol between each string.

< COALESCE FUNCTION SQL | COUNT Function SQL >


Send notes in disappearing ink!

Interesting Pages