RussellHarrower
RussellHarrower

Reputation: 6820

mysql group to columns

So i have to columns in my table one called spend and one save.

what I would like to do is join the two so that is says offers and has the spend|save

Say I have table as

spend    save
30       10

Output I want is

spend    save   dummyCol
30       10     30|10

Upvotes: 0

Views: 45

Answers (3)

John Woo
John Woo

Reputation: 263933

try this:

SELECT `spend`, `save`, CONCAT(`spend`, '|', `save`) as dummyCol 
FROM   `myTable`

Upvotes: 0

Fahim Parkar
Fahim Parkar

Reputation: 31647

Try below

SELECT spend, save, CONCAT(spend, '|', save) as dummyCol from myTable;

Here is link with more details.. Look for CONCAT.

Also look for CONCAT_WS. It is useful when you want to add SAME thing at many places...

Good Luck

Upvotes: 0

Michael Berkowski
Michael Berkowski

Reputation: 270775

So you just want to concatenate them? Use CONCAT_WS() to concatenate with a pipe separator:

SELECT CONCAT_WS('|', spend, save) AS spendsave FROM tbl;

Upvotes: 1

Related Questions