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've tried as well as others:

SELECT column1 + column2 AS column3
FROM table;

SELECT column1 || column2 AS column3
FROM table;

SELECT column1 + ' ' + column2 AS column3
FROM table;

Could someone please let me know what I'm doing wrong?

推荐答案

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)

Mysql相关问答推荐

我可以指示MariaDB-Install-db和MariaDB忽略配置中的用户设置吗?

SQL MaxSum查询为列 Select 了不正确的值

亚马逊RDS MySQL-无法';t执行';使用读取锁定刷新表';

提高bash脚本从大型gml文件读取数据的效率

按相关表中的计数和特定值过滤

如何在 SQL 中迭代所有名称和排名排列

如何在 WampServer 上重新初始化 MySQL 以允许 lower_case_table_names = 2

for each 查询设置 MySQL @@session.time_zone 而不是 CONVERT_TZ 的缺点?

MySQL CHECK 约束以确保记录不使用自动增量 ID 引用自身?

限制正则​​表达式中多字符通配符的范围

MYSQL LOAD DATA INFILE 语句适用于工作台,但不适用于 python

如何按给定开始日期和结束日期的月份汇总?

判断一对记录是否属于多个组ID

提高mysql导入速度

在 PHP 中获取 MySQL 列的总和

MySQL PHP - Select WHERE id = array()?

使用 mysql 处理非常大的数据

MySQL - 我如何输入 NULL?

MySQL where NOT IN 名称数组?

如何使用 Java 更改数据库连接中的 MySQL 时区?