Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Export values form almost 2 twin tables with the following conditions

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;

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading