Subject | Re: delete from table... best way? |
---|---|
Author | Sergio |
Post date | 2011-09-15T21:17:43Z |
> Not sure what your use is - but if you have t1.id_t2 defined as aThanks for answer! Probably I wasn't clear enough... here's an example:
> foreign key with cascading deletes, then you can never have a t2.id null
> and any delete of t1 will cascade and automatically delete the
> associated records in t2.
table "cars"
fields = id, car_name, id_driver
table "drivers"
fields = id, driver_name
table "cars" has a FK to table "drivers"
... foreign key (id_driver) references drivers(id)...
Now I want to delete all cars that *has* a record in "drivers", but the driver_name is null
so far, I always do
delete from cars
where
(
select drivers.driver_name
from drivers
where
cars.id_drivers = drivers.id
)
is null
that works fine, but I just wander if there is a better way... just for curiosity...
thanks!!
-s