How to combine multiple columns as one and format with custom strings?

Viewed 90270
SELECT id, <X> AS name FROM `table`

Basically <X> is a combination of
lastname + ', ' + firstname

example would be

   id | name        |
   2  | Smith, Bob  |
   3  | Jones, Susy |

This is just an example, I don't really want to combine names so simple.

4 Answers
SELECT 

CONCAT('https://example.com/estimation/create?pId=',task_p_id,'&estId=',task_est_id) as live_url,

CONCAT('http://stage.example.com/estimation/create?pId=',task_p_id,'&estId=',task_est_id) as stage_url 

FROM `ls_task` LEFT JOIN `ls_estimation` ON est_id=task_est_id LEFT JOIN `ls_project` ON p_id=task_p_id limit 10

You can use GROUP_CONCAT():

Example of getting all the column names of a table separated by comma:

SELECT GROUP_CONCAT(c.`COLUMN_NAME`) FROM information_schema.`COLUMNS` c
WHERE c.`TABLE_SCHEMA` = "DB_NAME" AND c.`TABLE_NAME`="TABLE_NAME"

Output:

column_name_1,column_name_2,column_name_3,column_name_4,...
Related