Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello need some help with this SQL/Oracle problem List the customer ID and Order

ID: 3597391 • Letter: H

Question

Hello need some help with this SQL/Oracle problem

List the customer ID and Order ID from the Orders table for all orders with order id greater than 700, and then delete the order with order ID = 1021. Then, show the total number of rows in the Orders table.

DELETE FROM orders
WHERE order_id = '1021' IN
(SELECT customer_id, order_id
FROM orders
WHERE order_id > 700)

From what this looks like it a DELETE statement that uses a subquery, however, the way that I wrote it, it's giving me the error "SQL command not properly ended".

Explanation / Answer

The problem in your query is subquery(inner query) returns 2 columns, but IN operator compares the values in one column, so it gives error.

and another reason you wrongly given that where order_id='1021' in

when you are using In you should not assign the value.

Here question is get the customer_id, order_id of customers whoose order_id more than 700 and from those delete customers whoose order_id=1021.

This actually means  get the customer_id, order_id of customers whoose order_id more than 700 and whoose order_id is not 1021.

Query:

  select customer_id,order_id from orders where order_id>700 and order_id<>1021;

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote