I have a Sales table that is very much related to many with a table Products For that reason, create the table DetailofProductsEnLaSale
CREATE TABLE IF NOT EXISTS DetalleDeLosProductosEnLaVenta (
ID_Productos INT NOT NULL,
ID_Ventas INT NOT NULL,
PRIMARY KEY ( ID_Productos , ID_Ventas ),
INDEX fk_Productos_has_Ventas_Ventas1_idx ( ID_Ventas ),
INDEX fk_Productos_has_Ventas_Productos1_idx ( ID_Productos ),
CONSTRAINT fk_Productos_has_Ventas_Productos1
FOREIGN KEY ( ID_Productos )
REFERENCES Productos ( ID_Productos )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT fk_Productos_has_Ventas_Ventas1
FOREIGN KEY ( ID_Ventas )
REFERENCES Ventas ( ID_Ventas )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
;
To erase sales made on a date, I first try to delete the relationship in the table DetailofProductsEnLaSale
DELETE DetalleDeLosProductosEnLaVenta.*
FROM DetalleDeLosProductosEnLaVenta
WHERE
DetalleDeLosProductosEnLaVenta.ID_Ventas =
(select Ventas.ID_Ventas from Ventas
where Ventas.Fecha = '2017/01/21' );
It happens that by that date there are more than two sales and I get the error
ERROR 1242 Subquery returns more than 1 row
I checked many pages like: Error 1242 Mysql subquery
Where you tell me to use limit 1, that is, limit to only deleting one.
I appreciate your cooperation ...