I have two tables with names tab1 and tab2.
tab1’s primary key is price and price is foreign key in tab2 and it is on delete set null.
When I delete one of primary key from tab1 that exists in tab2 the respective foreign key
is set to NULL.
Now I want to delete the row from tab2 where their foreign key is null.
I write this query but it does’t work.
delete from tab2 where price = null.
Please help me in solving it.
You can’t compare NULL using =. You should use
IS NULLinsteadFrom the MySQL Reference Manual
But if you are already using
on delete set null, why not simply change this toon delete cascadeand save you the trouble from deleting the rows manually?