This example illustrates how to append string of different column.
This example illustrates how to append string of different column.This example illustrates how to append string of different column.
In this example we create a table 'mca' with 'studentid', 'sectionid', 'courseid' and 'time'. In the table we insert value by using 'INSERT' query. The 'SELECT' query is used to append value of 'time' and 'sectionid' which display in the output below.
Query
CREATE TABLE mca (
studentid INT NOT NULL,
sectionid INT NOT NULL,
courseid INT NOT NULL PRIMARY KEY,
time VARCHAR(50)
);
Query
INSERT INTO mca (studentid,sectionid,courseid,time) VALUES (1,1,6,'Mon 09:30-11:00');
INSERT INTO mca (studentid,sectionid,courseid,time) VALUES (2,2,5,'Mon 11:30-12:00, Thu 09:00-11:00');
INSERT INTO mca (studentid,sectionid,courseid,time) VALUES (3,3,3,'Mon 14:30-16:00');
Query
SELECT studentid, CONCAT(time, ', section ', sectionid) AS ClassDetails FROM mca;
Output
+-----------+---------------------------------------------+ | studentid | ClassDetails | +-----------+---------------------------------------------+ | 3 | Mon 14:30-16:00, section 3 | | 2 | Mon 11:30-12:00, Thu 09:00-11:00, section 2 | | 1 | Mon 09:30-11:00, section 1 | +-----------+---------------------------------------------+