By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE tableA (
id int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
col1 int(11) NOT NULL,
col2 int(11) NULL,
PRIMARY KEY (id));
CREATE TABLE tableB (
id int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
tableA_id int(11) UNSIGNED NOT NULL,
count int(11) NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (tableA_id) REFERENCES tableA(id));
CREATE TABLE tableC (
id int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
tableB_id int(11) UNSIGNED NOT NULL,
quantity int(11) NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (tableB_id) REFERENCES tableB(id));
INSERT INTO tableA (col1,col2) VALUES(1,1);
INSERT INTO tableB (tableA_id,count) VALUES(1,10);
INSERT INTO tableC (tableB_id,quantity) VALUES(1,5);
INSERT INTO tableC (tableB_id,quantity) VALUES(1,5);
Select * from tableA;
Select * from tableB;
Select * from tableC;
id | col1 | col2 |
---|---|---|
1 | 1 | 1 |
id | tableA_id | count |
---|---|---|
1 | 1 | 10 |
id | tableB_id | quantity |
---|---|---|
1 | 1 | 5 |
2 | 1 | 5 |