(Find all correct answers)
See the scenario below:
create table stock (prod_id int primary key, amount decimal(10,2)); create table out_of_stock (prod_id int key); insert into stock values (1,100),(2,200),(3,10),(4,10); insert into out_of_stock values (1),(3);
The idea is to delete the rows in the stock table for all product ids listed in the out-of-stock table.
a) delete from stock where prod_id
in (select prod_id from out_of_stock);
b) delete stock v1 from stock v1
inner join out_of_stock v2 on (v1.prod_id=v2.prod_id) ;
c) delete from stock using stock
inner join out_of_stock v2 on (stock.prod_id=v2.prod_id) ;
d) delete stock.* from stock , out_of_stock
where stock.prod_id=out_of_stock.prod_id ;
[ Updating Data (10%) - The DELETE Statement ]
Answers:
a b c d
All the deletes work. The
USINGsyntax is also valid but harder to read, therefore I would recommend the syntax of b & d. Multi-table deletes can be very useful! b, c and d all use inner joins whereas a sub-query is used in a.