MySQL string concatenation function cancat () and Group_cancat ()

Source: Internet
Author: User

1.CONCAT () Stitching single-line string

Select concat (' + ', user_id) from table1;

Select Concat (' 11 ', ' 22 ', ' 33 ');
Results 112233

MySQL's concat function will return NULL if one is null when the string is concatenated.
Select Concat (' One ', ' n ', null);
Result NULL

2.group_cancat () stitching strings of all rows queried into a string to return

For example: I use Select Dictinct date from table1 to get the following table
200805
200806
200807
200808
200809
200810
200811
Now I need to stitch up this column of the resulting table into a string that
200805,200806,200807,200808,200809,200810,200811

Select Group_concat (dictinct date) from table1;

Select Group_concat(dictinct ' 001-', date) from table1; Stitching strings and returning different

  Back to 001-200805,001-200806,001-200807,001-200808,001-200809,001-200810,001-200811

MySQL string concatenation function cancat () and Group_cancat ()

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.