Use SQL to concatenate the values of multiple queried columns into a string _ MySQL

Source: Internet
Author: User
Concatenate the values of multiple queried columns into a string bitsCN.com using SQL.

Concatenate the values of multiple queried columns into a string using SQL.

MySQL:

[SQL]

-- Concatenate a single column. first, locate a row, add a comma, and then splice the next row.

Select group_concat (E. SUPPORT)

From ENGINES E

Where E. xa in ('yes', 'no ')

-- The result is as follows: YES, YES, DEFAULT, YES

-- Replace ",", and "**" in the query result

Select REPLACE (group_concat (E. SUPPORT ),',','**')

From ENGINES E

Where E. xa in ('yes', 'no ')

-- The result is as follows: YES ** DEFAULT ** YES

-- Remove duplicate records from the query results, with only one record left, and then splice

Select group_concat (DISTINCT (E. SUPPORT ))

From ENGINES E

Where E. xa in ('yes', 'no ')

-- The result is as follows: YES, DEFAULT

-- Concatenates multiple columns, concatenates the same row first, and then concatenates the next row with a comma.

Select group_concat (E. ENGINE, E. SUPPORT)

From ENGINES E

Where E. xa in ('yes', 'no ')

-- The result is as follows: MRG_MYISAMYES, MyISAMYES, BLACKHOLEYES, CSVYES, MEMORYYES, ARCHIVEYES, InnoDBDEFAULT, cece_schemayes

BitsCN.com

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.