I have 3 tables, "cars", "elements" and "element_status" (for example). I'm NOT able to modify the SQL structure. Here's the code:
CREATE TABLE cars(
idCar VARCHAR(60) NOT NULL,
CONSTRAINT PK_cars_idCar PRIMARY KEY (idCar));
CREATE TABLE elements(
idElement VARCHAR(30) NOT NULL,
idCar VARCHAR(60) NOT NULL,
CONSTRAINT FK_elements_idCar FOREIGN KEY (idCar) REFERENCES cars(idCar),
CONSTRAINT PK_elements_idElement_idCar PRIMARY KEY (idElement, idCar));
CREATE TABLE element_status(
idElement VARCHAR(30) NOT NULL,
status BOOLEAN NOT NULL,
CONSTRAINT FK_status_idelement FOREIGN KEY (idElement) REFERENCES elements(idelement),
CONSTRAINT PK_status_idElement PRIMARY KEY (idElement));
So, here's the plot. Each element has a row in element_status. Each element_status row references one element and that element references one car.
So I have a row in "element_status" with idElement="engine" and status=FALSE. This engine references an engine in "elements" with, let's say, idCar="car_1234". But there a lot of engines there, each one pointing to it's car.
I need to update the status to TRUE in "element_status" of the engine with idCar="car_1234" and I need help with it. My mind says it should be easy, (subquery I guess) but actually i don't know how to do it.
Thanks!!