Mysql combines multiple data entries corresponding to the same ID.

Source: Internet
Author: User

Mysql combines multiple data entries corresponding to the same ID.

This example describes how to merge multiple data entries with the same ID in mysql. We will share this with you for your reference. The details are as follows:

For example:

CREATE TABLE `c_classuser_tab` ( `Id` int(11) NOT NULL AUTO_INCREMENT, `Classid` int(11) DEFAULT NULL, `Username` varchar(100) DEFAULT NULL, `studentid` varchar(100) DEFAULT NULL, `College` varchar(100) DEFAULT NULL, `Department` varchar(100) DEFAULT NULL, `Email` varchar(100) DEFAULT NULL, `Phone` varchar(100) DEFAULT NULL, `Status` int(11) DEFAULT NULL, `Remark1` varchar(100) DEFAULT NULL, `Remark2` varchar(100) DEFAULT NULL, `Remark3` varchar(100) DEFAULT NULL, `activateTime` datetime DEFAULT NULL, `joinTime` datetime DEFAULT NULL, `userID` int(11) DEFAULT NULL, `userType` int(11) DEFAULT NULL, PRIMARY KEY (`Id`), KEY `C_classuser_tab_index` (`studentid`), KEY `idx_classuser_complex` (`Classid`,`userID`)) ENGINE=MyISAM AUTO_INCREMENT=31091 DEFAULT CHARSET=utf8;

Teachers with the same ID have multiple substitute classes and merge them,

Instructor substitute Class

Class 12, Class 2
Copy codeThe Code is as follows: select Username, GROUP_CONCAT (Remark1, '') as classes from c_classuser_tab where userID = * and userType = *

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.