Say I have this select statement:
SELECT ut.user_id,
a.firstname,
a.surname,
u.username,
u.email_address
FROM administrators a
JOIN user_types ut JOIN users u ON a.admin_id = ut.type_id
AND u.user_id = ut.user_id AND ut.user_type = 'ADMIN';
Say I wanted to update ALL values in the row where user_id = 1;
I could update EACH TABLE individually OR i could create a view like so:
CREATE OR REPLACE VIEW full_admin AS
SELECT ut.user_id,
a.firstname,
a.surname,
u.username,
u.email_address
FROM administrators a
JOIN user_types ut
JOIN users u on a.admin_id = ut.type_id
AND u.user_id = ut.user_id
AND ut.user_type = 'ADMIN'
Then I could write:
UPDATE full_admin
SET firstname = 'blah', etc, etc
WHERE user_id = 1;
And that will update all rows in all tables
Is there a way to do this WITHOUT creating a view?
Something like:
UPDATE (
SELECT ut.user_id,
a.firstname,
a.surname,
u.username,
u.email_address
FROM administrators a
JOIN user_types ut
JOIN users u ON a.admin_id = ut.type_id
AND u.user_id = ut.user_id
AND ut.user_type = 'ADMIN'
)
AS temp_table
SET firstname = "ALEX"
WHERE user_id = 1;
However that doesnt work