Concatenate multiple mysql fields and mysql Fields

Source: Internet
Author: User

Concatenate multiple mysql fields and mysql Fields

The following two functions can be used to concatenate the query result line Fields of Mysql:

1. concat Function

mysql> select concat('1','2','3') from test ;+---------------------+| concat('1','2','3') |+---------------------+| 123 |+---------------------+
If NULL exists in the connection string, the returned result is NULL:
mysql> select concat('1','2',NULL,'3') from test ;+--------------------------+| concat('1','2',NULL,'3') |+--------------------------+| NULL |+--------------------------+

2. concat_ws Function

Concat (separator, str1, str2,...) represents concat with separator, which is a special form of concat. The first parameter is the delimiter of other parameters. The separator is placed between the two strings to be connected. The delimiter can be a string or another parameter.

mysql> select concat_ws(':','1','2','3') from test ;+----------------------------+| concat_ws(':','1','2','3') |+----------------------------+| 1:2:3 |+----------------------------+
If the Delimiter is NULL, the returned result is NULL:

mysql> select concat_ws(NULL,'1','2','3') from test; +-----------------------------+| concat_ws(NULL,'1','2','3') |+-----------------------------+| NULL | +-----------------------------+


If NULL exists in the parameter, it will be ignored:

mysql> select concat_ws(':','1','2',NULL,NULL,NULL,'3') from test ;+-------------------------------------------+| concat_ws(':','1','2',NULL,NULL,NULL,'3') |+-------------------------------------------+| 1:2:3 |+-------------------------------------------+

NULL can be judged and replaced with other values:

mysql>  select concat_ws(':','1','2',ifNULL(NULL,'0'),'3') from bank limit 1;  +---------------------------------------------+| concat_ws(':','1','2',ifNULL(NULL,'0'),'3') |+---------------------------------------------+| 1:2:0:3                                     | +---------------------------------------------+





How does mysql add multiple fields to a table at a time?

This should be added

Alter table mytable add FIELD1 VARCHAR (10), ADD FIELD2 INT, ADD FIELD3 VARCHAR (1)

How to update the values of multiple fields in mysql?

Update table name set name = ?, Password = ?.... Where id =?

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.