2013-07-22 43 views
-2

我已經搜索了這個答案,找不到任何地方。反正我不太想要。Mysql結合多列的值

我有一個表中有五個Mysql列,我想合併爲一列。

column1value | column2value | column3value | column4value | column5value 

需要變得

column1valuecolumn2valuecolumn3valuecolumn4valuecolumn5value 

在一個列(列1)。我需要爲每一行都發生這種情況。

非常感謝提前。

+0

爲什麼不能使用'concat'功能? – Sebas

+0

@Sebas問題或許OP不知道'concat'函數 – bugwheels94

回答

4

如果你只是想找回組合在時尚中的數據:

SELECT CONCAT(
     column1value, 
     column2value, 
     column3value, 
     column4value, 
     column5value 
     ) column1value 
FROM my_table 

如果要永久更新表中的數據:如果您還想要刪除

UPDATE my_table 
SET column1value = CONCAT(
     column1value, 
     column2value, 
     column3value, 
     column4value, 
     column5value 
     ) 

舊列:

ALTER my_table 
    DROP column2value, 
    DROP column3value, 
    DROP column4value, 
    DROP column5value 
+0

非常感謝 – user2227359

0

你可以這樣做

select concat(column1value,column2value,column3value,column4value,column5value) 
    AS allvalues from table1 

little demo here

是所有在列1

UPDATE my_table 
    SET column1 = CONCAT(column1value,column2value,column3value,column4value,column5value 
    )