I want to make a project for myself and I don't know how to make to export values from almost 2 twin tables with the following condition if stock general quantity =<5 then export id, name, quantity into urgent table my query is this one
CREATE TABLE IF NOT EXISTS `Spital`.`Stoc General`
(
`ID Produs` INT,
`Denumire` VARCHAR(45) NOT NULL,
`Cantitate` INT NULL,
PRIMARY KEY (`ID Produs`)
)
ENGINE = InnoDB;
SELECT * FROM `Spital`.`Stoc General`;
INSERT INTO `spital`.`stoc general` (`ID Produs`, `Denumire`, `Cantitate`)
VALUES ('1', 'Clabax', '20');
INSERT INTO `spital`.`stoc general` (`ID Produs`, `Denumire`, `Cantitate`)
VALUES ('2', 'Betadina', '15');
INSERT INTO `spital`.`stoc general` (`ID Produs`, `Denumire`, `Cantitate`)
VALUES ('3', 'Paracetamo', '4');
INSERT INTO `spital`.`stoc general` (`ID Produs`, `Denumire`, `Cantitate`)
VALUES ('4', 'Oxigen', '3');
CREATE TABLE IF NOT EXISTS `Spital`.`Stoc URGENT`
(
`ID Produs` INT NOT NULL AUTO_INCREMENT,
`Denumire` VARCHAR(45) NOT NULL,
`Cantitate` INT NOT NULL,
`Date Delivery` DATETIME NULL,
PRIMARY KEY (`ID Produs`)
)
ENGINE = MEMORY;
CodePudding user response:
use INSERT INTO Statement that enable you to Insert data into Specified Columns
INSERT INTO `spital`.`stoc urgent`
(`id produs`,
`denumire`,
`cantitate`)
SELECT `id produs`,
`denumire`,
`cantitate`
FROM `spital`.`stoc general`
where `cantitate`<5