Q. Given the following tables:

Orders (OrdNo, Ord_date, ProdNo#, Qty)

Product (ProdNo, Descp, Price)

Payment (OrdNo, Pment)

Write a query to delete all those records from table Orders whose complete payment has been made.


Answer :-

DELETE FROM Orders
WHERE Orders.OrdNo = Payment.OrdNo and Orders.ProdNo=Product.ProdNo
AND Payment.Pment = Orders.Qty * Product.Price ;

Explaination :-

At first, I have to make a condition to linking the order, payment, and product table then make another condition that will check whether is payment done by the customer is equal to the price of the product * quantity.


25 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. hello thnk u

    ReplyDelete
  2. Plz can you explain from where order how you write this query ?

    ReplyDelete
    Replies
    1. At first i have make condition to link order and payment table then make another condition that will check 'is payment done by customer is equal to price of product * quantity.

      Delete
  3. What was the need for second condition?

    ReplyDelete
  4. Will the Product No matter here?

    ReplyDelete
  5. i am writing the query but it is showing error

    ReplyDelete
    Replies
    1. I think you have write wrong spelling. So, please correct it then tell me.

      Delete
  6. delete from orders natural join payment where pment is not null; ?

    ReplyDelete
  7. DELETE FROM Orders
    WHERE Orders.OrdNo = Payment.OrdNo and Orders.ProdNo=Product.ProdNo
    AND Payment.Pment = Orders.Qty * Product.Price ;

    ReplyDelete
  8. one day before computer science exam!....who else is here??

    ReplyDelete
  9. Thanks, this cleared my doubts!

    ReplyDelete
  10. This will never work. I tried doing this by making demo tables and MySQL cannot identify any of the columns from the different tables referred like "tablename.columnname" despite the 3 tables (orders, product, payment) being in the same database.
    The "tablename.columnname" only works in select statements where you mention what table the table alias in the "tablename.columnname" refers to. Say, "SELECT tablename.columnname" FROM tablename" then in this syntax, MySQL would understand what table is the column name in.

    ReplyDelete
  11. Is it a good question for exam?

    ReplyDelete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post