Combine Two mysql columns and one mysql Column

Source: Internet
Author: User

Combine Two mysql columns and one mysql Column

For example, if there are two columns: surname and name, the query result is one column. The concat keyword is required. The SQL statement is as follows:

select concat(firstName,lastName) from tj_user



Merge two mysql Columns

Use the following SQL statement to delete the Adress2 column:
Update Adress set Adress1 = concate (Adress1, Adress2)

How to add a column between two columns in mysql

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;
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.