I have 2 tables:
CREATE TABLE IF NOT EXISTS t1
(
id UUID NOT NULL,
last_login TIMESTAMP,
PRIMARY KEY (id)
);
CREATE TABLE IF NOT EXISTS t2
(
id UUID NOT NULL,
t1_id UUID NOT NULL,
PRIMARY KEY (id),
CONSTRAINT ids
FOREIGN KEY (t1_id)
REFERENCES t1 (id)
ON DELETE CASCADE
ON UPDATE NO ACTION
);
and I want to select a row from t2 and update the last_login timestamp of the corresponding t1 id in the t1 table.
Is it possible to do this in a single query?
You can't both UPDATE
and SELECT
in the same SQL operation. You have some options though: