mysql两列合成一列,mysql两列一列
比如:有姓和名两列,我想查询的结果为一列。就需要concat关键字了。sql如下:
select concat(firstName,lastName) from tj_user
使用下面的SQL语句,运行一次后就何必了,然后就可以删除Adress2列:
update Adress set Adress1=concate(Adress1,Adress2)
mysql> CREATE TABLE TESTTABLE(
-> A INT DEFAULT 0,
-> B INT DEFAULT 0
-> )ENGINE=INNODB DEFAULT CHARSET=UTF8;
Query OK, 0 rows affected
mysql> DESC TESTTABLE;
+-------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| A | int(11) | YES | | 0 | |
| B | int(11) | YES | | 0 | |
+-------+---------+------+-----+---------+-------+
2 rows in set
mysql> ALTER TABLE TESTTABLE ADD COLUMN C INT DEFAULT 0 AFTER A;
Query OK, 0 rows affected
Records: 0 Duplicates: 0 Warnings: 0
mysql> DESC TESTTABLE;
+-------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| A | int(11) | YES | | 0 | |
| C | int(11) | YES | | 0 | |
| B | int(11) | YES | | 0 | |
+-------+---------+------+-----+---------+-------+
3 rows in set