+ 1
SQL --> CONCAT command
can you explain the need for extra commas before and after the field names here SELECT CONCAT(FirstName,', ', City) please?
2 Respuestas
+ 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.
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