MySQL character join function concat usage

Source: Internet
Author: User
Tags mysql tutorial

MySQL Tutorial character join function Concat usage

There are two Concat_ws (), concat () functions in MySQL character or field content join functions, let's look at their simple examples.


Concat (STR1,STR2,...)

Returns a string resulting from a connection parameter. If any of the arguments are null, the return value is null.

Mysql> Select Concat (' My station ', ' yes ', ' www.111cn.net ');

-> ' My station is Www.111cn.net '

It's a simple example, and we'll follow the database tutorial

Database structure
CREATE table if not EXISTS ' test ' (
' ID ' int (4) NOT NULL auto_increment,
' C ' text,
' B ' text,
Primary KEY (' ID ')
) Engine=myisam default charset=gb2312 auto_increment=7;

Inserting data
INSERT INTO ' test ' (' id ', ' C ', ' B ') values
(1, ' Fdsa ', ' FDSA '),
(2, ' FDA ', ' FDA '),
(5, ' vvvv ', ' fdsadddd ');


Instance

Select Concat (b, ' www.111cn.net ')
From ' Test '
where 1
Limit 0, 30

Results

Concat (b, ' www.111cn.net ')
Fdsawww.111cn.net
Fdawww.111cn.net
Fdsaddddwww.111cn.net

Concat_ws (SEPARATOR,STR1,STR2,...) functions, they suddenly all null, but do not remove spaces

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.