Results 1 to 3 of 3

Thread: Joining same table & update query

  1. #1
    Join Date
    Sep 2011
    Posts
    13
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Joining same table & update query

    Demo Table: orders
    orderid amount disc_amt actual_amount
    1000 500 100 500
    2000 600 200 600
    3000 400 200 400

    Now I am having a requirement that to update actual_amount of each order that is subtracted by disc_amt.

    I want to know what should be the update query?

    Please Help.

    Thanks
    Kaushal.
    Last edited by kaushal; 03-06-2012 at 09:45 AM.

  2. #2
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    1,692
    Thanks
    82
    Thanked 90 Times in 88 Posts

    Default

    If I am understanding you correctly you want to update your orders table so that the actual_amout reads actual_amount - disc_amt.

    Try this:

    Code:
    UPDATE orders SET actual_amount=(actual_amount - disc_amt)
    This will update all of the rows in your orders table changing the actual_amount to actual_amount minus disc_amt.
    Last edited by james438; 03-10-2012 at 02:15 AM. Reason: added highlighting. Corrected very tiny error unrelated to code.
    To choose the lesser of two evils is still to choose evil. My personal site

  3. #3
    Join Date
    Sep 2011
    Posts
    13
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Joining same table & update query

    Wow James what a magic...
    You are awesome.
    Thank you for helping me.
    Thanks again.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •