-1

I have a scenario where I'd like to get columns with information stored in a very specific way. I'd like to select n number of columns from a table A, concatinate their values, and then add m number of more values which should be grabbed from other tables by joining one of their columns to the current statement's column.

  • Cars - (car_id, model_id, plate_id, brand_name, year_of_release, custom_column)
  • Model - (model_id, model_name, description)
  • Plates - (plate_id, car_owner_name, registration_state)

Let's say we have these tables and what we want to do is place the following information in one column:

'car_id, brand_name, year_of_release, plate_id, model_name, car_owner_name, registration_state'

for each row of the Cars table as a 'custom_column' value

I'd like it to be a comma-separated string. Is there a way to do this with MySQL?

philipxy
  • 14,867
  • 6
  • 39
  • 83
Nata Vacheishvili
  • 387
  • 1
  • 5
  • 18
  • 1
    This is a faq. Before considering posting please read your textbook and/or manual & google any error message or many clear, concise & precise phrasings of your question/problem/goal, with & without your particular strings/names & site:stackoverflow.com & tags; read many answers. If you post a question, use one phrasing as title. Reflect your research. See [ask] & the voting arrow mouseover texts. – philipxy May 19 '20 at 23:18

1 Answers1

1

You seem to want concat_ws():

select concat_ws(', ', car_id, brand_name, year_of_release, plate_id, model_name, car_owner_name, registration_state)
from t;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786