Mysql Group_concat () function splicing string

Source: Internet
Author: User

SELECT Group_concat (Ut.id_card ORDER by Ut.id_card DESC SEPARATOR ', ') from ' Edu_user_train ' ut where ut.id in (614,615 ) Output: 500231199108181861,371324198450304515 usage Scenario: Returns a pure numeric mate in query example: SELECT u.name from ' edu_user ' u WHERE u.id_card in ( 500231199108181861,371324198450304515);
Select Group_concat (' "', Ut.id_card, '" ') from ' Edu_user_train ' ut where ut.id in (614,615); output: "500231199108133881", " 371325198706304515 "Usage Scenario: Returns the string (because there is an" X "in the ID) with the in query example: SELECT u.name from ' edu_user ' u WHERE u.id_card in (" 500231199108133881 "," 371325198706304515 ");
Select CONCAT (' "', Ut.id_card, '" ') from ' Edu_user_train ' ut where ut.id in (614,615); output: "500231199133133881" " 371325198706454515 "This is a relatively small case.

The difference between this section and the above is that when you add a group, you get a result and you wrap the line.

SELECT group_concat (U. Name ORDER by U. Name DESC SEPARATOR ",") as UserName from ' edu_user ' u WHERE u.id_card in (sele CT Ut.id_card from the ' Edu_user_train ' ut where ut.id in (614,615,939)); multiple data, subquery.

Welcome to add , this is my practice in the record, detailed usage and professional explanations please see the MySQL API.

Mysql Group_concat () function splicing string

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.