Adding Multiple Rows to a Table
/* Create the table */
Drop TABLE Professor;
Drop TABLE Student;
CREATE TABLE Professor (
ProfessorID INT NOT NULL PRIMARY KEY,
Name VARCHAR(50) NOT NULL)
TYPE = InnoDB;
CREATE TABLE Student (
StudentID INT NOT NULL PRIMARY KEY,
Name VARCHAR(50) NOT NULL
)TYPE = InnoDB;
/* Prepare the data */
INSERT INTO Student (StudentID,Name) VALUES (1,'John Jones');
INSERT INTO Student (StudentID,Name) VALUES (2,'Cury Butz');
INSERT INTO Student (StudentID,Name) VALUES (3,'JJ Smith');
/* Real command */
INSERT INTO Professor (ProfessorID, Name)
SELECT StudentID + 7, Name
FROM Student;
Related examples in the same category