Which DELETE statement are valid?

View the Exhibit and examine the structure of ORDER_ITEMS and ORDERS tables. You need to remove from the ORDER_ITEMS table those rows that have an order status of 0 or 1 in the ORDERS table. Which DELETE statements are valid? (Choose all that apply.)

View the Exhibit and examine the structure of ORDER_ITEMS and ORDERS tables.

You need to remove from the ORDER_ITEMS table those rows that have an order status of 0 or 1 in the ORDERS table.

Which DELETE statements are valid? (Choose all that apply.)

A.
DELETE
FROM order_items
WHERE order_id IN (SELECT order_id
FROM orders
WHERE order_status in (0,1));

B.
DELETE *
FROM order_items
WHERE order_id IN (SELECT order_id
FROM orders
WHERE order_status IN (0,1));

C.
DELETE FROM order_items i
WHERE order_id = (SELECT order_id FROM orders o
WHERE i.order_id = o.order_id AND
order_status IN (0,1));

D.
DELETE
FROM (SELECT * FROM order_items i,orders o
WHERE i.order_id = o.order_id AND order_status IN (0,1));



Leave a Reply 11

Your email address will not be published. Required fields are marked *


Milenko Burlica

Milenko Burlica

I’m confused with D 🙂

ERROR at line 1:
ORA-01752: cannot delete from view without exactly one key-preserved table

Caz

Caz

Hi,

I ran SQL ‘D’ against the Oracle test schema and the SQL ran successfully….

DELETE
FROM (SELECT * FROM order_items i,orders o
WHERE i.order_id = o.order_id AND order_status IN (0,1));

110 rows deleted.

Regards

user

user

For C, the equal operator cannot be used because the subquery may return 2 rows.

yassine

yassine

it will return 1 row because we specify the ‘i.order_id’ from the outer query , and as you now the order_id is the primary key in the to table, sow it’s impossible to find the same value too time.

vinoth

vinoth

A and D

B incorrect because cant use * for delete syntax

C is incorrect because the order_id may return more than one row so IN clause should be used.

dames

dames

A,C,D
Tested. They delete identically on OE schema.

A – Delete using WHERE clause using IN operator
C – Delete using correlated subquery
D – Delete using inline view. You can delete only one table at the time and ORDER_ITEMS is the only key-preserved table.

shadow

shadow

Nice Explanation Thank you Dams (:-)

look what i found

look what i found

When I originally left a comment I appear to have clicked the -Notify me when new comments are added- checkbox and now whenever a comment is added I recieve 4 emails with the same comment. Is there a means you are able to remove me from that service? Thanks a lot!|

Info

Info

Awesome blog! Do you have any recommendations for aspiring writers? I’m hoping to start my own website soon but I’m a little lost on everything. Would you propose starting with a free platform like WordPress or go for a paid option? There are so many options out there that I’m completely confused .. Any suggestions? Appreciate it!|