I have two tables:
CREATE TABLE tblEatables (
`EatId` int UNSIGNED PRIMARY AUTO_INCREMENT,
`Fruits` varchar(9) NOT NULL
) Engine=InnoDB;
CREATE TABLE tblConfirm_Eatables (
Eatables_Id INT UNSIGNED,
Edible_Status INT,
FOREIGN KEY Eatables_Id REFERENCES tblEatables (EatId)
) Engine=InnoDB;
I want to select all the tblEatables.Fruits which are in tblConfirm_Eatables that have an Edible_Status of 0, and those which are not in tblConfirm_Eatables.
Sample data:
INSERT INTO tblEatables
(`EatId`, `Fruits`)
VALUES
(1, 'Apples'),
(2, 'Oranges'),
(3, 'Papaya'),
(4, 'Jackfruit'),
(5, 'Pineapple'),
(6, 'Mango');
INSERT INTO tblConfirm_Eatables
VALUES
(1,0),
(2,1),
(3,0),
(4,0);
The results should be:
Fruits Apple Papaya Jackfruit Pineapple Mango
Note “Orange” is not there since it has an edible status of “1”.
Try This