Mysql merges a single field of multiple records to edit one record _ MySQL
Source: Internet
Author: User
Mysql merges a single field of multiple records to edit the bitsCN.com Test table structure with one record:
--
-- Table structure 'Tet'
--
Create table if not exists 'Tet '(
'Id' int (11) not null,
'Name' varchar (255) not null,
'URL' varchar (255) NOT NULL
) ENGINE = InnoDB default charset = utf8;
--
-- Store the data in the table 'Tet'
--
Insert into 'Tet' ('id', 'name', 'URL') VALUES
(1, 'Baidu ', 'http: // www.baidu.com '),
(0, 'Google ', 'http: // www.google.com.hk '),
(3, 'phone 400 ', 'http: // www.bitsCN.com ');
Method 1:
SELECT GROUP_CONCAT (name) name
FROM tet
WHERE 1 = 1
LIMIT 0, 30
Result:
Name: Baidu, google, 400 phone number
GROUP_CONCAT can also use the SEPARATOR keyword to specify the connector. the SQL statement is as follows:
SELECT GROUP_CONCAT (url SEPARATOR "@") url
FROM tet
WHERE 1 = 1
LIMIT 0, 30
Result:
Http://www.baidu.com @ http://www.google.com.hk @ http://www.bitsCN.com
Method 2:
SELECT GROUP_CONCAT (name) name
FROM tet
WHERE 1 = 1
Group by id
LIMIT 0, 30
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.