MySQL combine two columns into one column

后端 未结 10 944
后悔当初
后悔当初 2020-11-29 00:46

I\'m trying to find a way to combine two columns into one, but keep getting the value \'0\' in the column instead to the combination of the words.

These are what I\'

相关标签:
10条回答
  • 2020-11-29 01:43

    It's work for me

    SELECT CONCAT(column1, ' ' ,column2) AS newColumn;
    
    0 讨论(0)
  • 2020-11-29 01:43

    This is the only solution that would work for me, when I required a space in between the columns being merged.

    select concat(concat(column1,' '), column2)
    
    0 讨论(0)
  • 2020-11-29 01:43
    convert(varchar, column_name1) + (varchar, column_name)
    
    0 讨论(0)
  • 2020-11-29 01:44

    My guess is that you are using MySQL where the + operator does addition, along with silent conversion of the values to numbers. If a value does not start with a digit, then the converted value is 0.

    So try this:

    select concat(column1, column2)
    

    Two ways to add a space:

    select concat(column1, ' ', column2)
    select concat_ws(' ', column1, column2)
    
    0 讨论(0)
提交回复
热议问题