Test Table Structure:
Copy codeThe Code is as follows:
--
-- 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.jb51.net ');
Method 1:
Copy codeThe Code is as follows:
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.jb51.net
Method 2:
Copy codeThe Code is as follows:
SELECT GROUP_CONCAT (name) name
FROM tet
WHERE 1 = 1
Group by id
LIMIT 0, 30
Result:
Google
Baidu
400 phone