I just learned the FROM and derived tables in mysql, and most websites have provided examples using the SELECT command
Example SELECT * FROM (SELECT * FROM usrs) as u WHERE u.name = 'john'
But when I tried to use the delete or update command, it does not work.
Example DELETE FROM (SELECT * FROM usrs) as u WHERE u.name = 'john'
1064 - You have an error in the SQL syntax; check the manual that matches the version of your MySQL server for the correct syntax to use next (SELECT * FROM usrs) as u WHERE u.name = 'john' in the line
UPDATE (SELECT * FROM usrs) as u SET u.lname ='smith' WHERE u.name = 'john'
1288 Target table e UPDATE not updated
So, views don't work with delete or update commands? or is there a way to make it work.
Instead of writing the table name for updating and deleting, I want to write a subquery that receives the records and performs the delete operation on these records? Is this possible in mysql?
UPDATED I need to delete a record, and I have three tables, a record can exist in any table
My approach is delete from first table rows effected? quit: else check second table rows effected? quit : else check third table delete from first table rows effected? quit: else check second table rows effected? quit : else check third table
But if I use UNION ALL , I can do it
Delete from (select * from tb1 union all select * from tb2 union all select * from tb3) e as e.uname = 'john'
but this query does not seem to work, now someone can tell me how to delete or update the record when I have more than one table to search. Any help is appreciated.