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));
I’m confused with D 🙂
ERROR at line 1:
ORA-01752: cannot delete from view without exactly one key-preserved table
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
For C, the equal operator cannot be used because the subquery may return 2 rows.
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.
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.
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.
Nice Explanation Thank you Dams (:-)
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!|
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!|
I value the blog.Really looking forward to read more. Cool.
http://www.scoop.it/t/internet-by-johnsmith3755102/p/4054379125/2015/10/30/houston-internet-marketing-company
Enjoyed every bit of your blog article. Much obliged.
http://independencescience.co/internet/open-air-photo-booth-san-diego/