SQL --> CONCAT command | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

SQL --> CONCAT command

can you explain the need for extra commas before and after the field names here SELECT CONCAT(FirstName,', ', City) please?

31st Jan 2017, 6:32 AM
Hamid
Hamid - avatar
2 Answers
+ 2
Let's say you have the following data: FirstName = Adam City = New York City Assuming that you have inserted these data into a table. Then, you would want to concatenate these together, logically it would be "AdamNew York City". This does not look nice, and thus you would want it to be "Adam,New York City". In SQL, you would do SELECT CONCAT(FirstName, ',', City) from *your table* to form something like this: +------------------------------------+ | CONCAT(FirstName, ',', City) | +------------------------------------+ | Adam,New York City | +------------------------------------+ So, the CONCAT function literally takes the values supplied to it and add them all together. If you put a space instead of a comma, it will be "Adam New York City" instead of "AdamNew York City". To answer your question, the comma in between is just to format the result so that it will look nicer. There is really nothing in particular as to why the commas are so special.
31st Jan 2017, 6:52 AM
Deddy Tandean
0
How do I CONCAT and give a space. Like if the statement is supposed to read Firstname Lastname, Salary. Every time I CONCAT it adds the commas
28th Jun 2021, 7:28 PM
Montgomery Jackson
Montgomery Jackson - avatar