mardi 27 août 2019

I can't run this query, but when i simulate it in phpmyadmin, it returns the rows

I'm going to delete some rows in one of my table called 'sy_user'. I want to delete some of the rows that is not matched in the other table, which is the 'tb_master_pegawai'. How do i solve this query to do the row delete using the subquery as the WHERE condition?

I used subquery as the WHERE condition in the DELETE query. When i run it in phpmyadmin it says "You can't specify target table 'sy_user' for update in FROM clause" but when i simulate it, it has return rows.

DELETE FROM sy_user 
       WHERE user_id NOT IN 
                (SELECT tbpeg.ID 
                 FROM tb_master_pegawai AS tbpeg 
                 JOIN sy_user AS tbuser ON tbpeg.ID=tbuser.user_id)

i expect the result is i have deleted the rows that are not matched with the same data in the other table.




Aucun commentaire:

Enregistrer un commentaire