1

I've got several records in a temp table, and I'd like to take a value from each record and add it to a variable, e.g.

color          | caption
--------------------------------
red              stop
blue             state line
yellow           yield
orange           construction

var1 = 'red;blue;yellow;orange'

In MSSQL, I could do that this way:

-- MSSQL
select var1 = var1 + color
from signShapes

In MySQL, that doesn't work. I'd just get "orange."

-- mySQL
select var1 = concat(var1, color)
from signShapes

No, I know I could accomplish this with a cursor or a loop. I'm curious if I could do this without either, similarly to the MSSQL method.

2 Answers 2

2
 SELECT var1 = GROUP_CONCAT(color SEPARATOR ';')
 FROM signShapes
 GROUP BY color;
Sign up to request clarification or add additional context in comments.

1 Comment

In the hopes of one day converting our company's rdbms to MySQL, I'm doing a few personal projects first to get a solid handle on things. I'm learning something new every day.
1

Why not just do this?

select var1 = group_concat(color separator ';')
from signShapes;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.