insert many to many sql

Solutions on MaxInterview for insert many to many sql by the best coders in the world

showing results for - "insert many to many sql"
Eleonora
29 Nov 2019
1INSERT INTO persons (firstname,lastname) VALUES ('John','Doe');
2SET @person_id = LAST_INSERT_ID();
3
4INSERT IGNORE INTO properties (property) VALUES ('property_A');
5SET @property_id = LAST_INSERT_ID();
6INSERT INTO has_property (person_id,property_id) VALUES(@person_id, @property_id);
7
8INSERT IGNORE INTO properties (property) VALUES ('property_B');
9SET @property_id = LAST_INSERT_ID();
10INSERT INTO has_property (person_id,property_id) VALUES(@person_id, @property_id);
11
12INSERT IGNORE INTO properties (property) VALUES ('property_C');
13SET @property_id = LAST_INSERT_ID();
14INSERT INTO has_property (person_id,property_id) VALUES(@person_id, @property_id);