I have joined three tables into a view, and then i try to update the view and get this error
#1393 - Can not modify more than one base table through a join view
ER_VIEW_MULTIUPDATE
I understand the error. I cannot update multiple tables at once.
HOWEVER… I have done this before. Last week to be precise, on the same machine, same mysql installation.
I promise you that I have joined together tables through a view before (the same tables infact) and updated the view with no problems.
Does anybody know why its not working?
The PHP code that worked last week
"UPDATE administrators AS a INNER JOIN user_types AS ut ON a.admin_id = ut.type_id INNER JOIN users AS u ON u.user_id = ut.user_id SET a.firstname = '{$user_input["firstname"]}', a.surname = '{$user_input["surname"]}', u.email_address = '{$user_input["email_address"]}' WHERE u.user_id = {$user_input["user_id"]}"
The SQL code im trying now
CREATE VIEW admin_users AS
SELECT administrators ad
JOIN user_types ut
ON ad.admin_id = ut.type_reference
JOIN users us
ON ut.user_id = us.user_id
WHERE ut.user_type = 'ADMIN'
UPDATE admin_users
SET
firstname = 'alex2',
surname = 'finch2',
email_address = 'test@hotmail.co.uk'
WHERE
user_id = 2
The SQL that worked last week was a direct
UPDATEquery that modified tables, whereas you’re now attempting toUPDATEthose same tables through a view. That’s the change. With aVIEW, you can only update one table at a time. You might look into stored procedures if you want to update multiple tables with one query.Something like this:
To call: