Do an UPDATE using a LEFT OUTER JOIN

  • Hello,

    I need help writing a basic query. I do not have much experience using any types of JOINS inside an UPDATE query, so I appreciate any help offered.

    If the values for B table fields are null, i.e. already removed, then the status on A table should be set to "Contacted"

    The joining filed on this two tables will be customer_id

    In advance, thank you very much. 🙂

  • Please read ... http://www.sqlservercentral.com/articles/Best+Practices/61537/ ... and repost your question. 😀

    This also seems like a homework question. What have you tried already?

    ______________________________________________________________________

    Personal Motto: Why push the envelope when you can just open it?

    If you follow the direction given HERE[/url] you'll likely increase the number and quality of responses you get to your question.

    Jason L. Selburg
  • update a

    set fieldone = 'contacted'

    from tableONE a

    left join tableTWO b on a.customerID = b.customer_id

    where b.customer_id is null

  • From the description, the code looks correct... did you try it?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Yes I did try it and it seems to work fine. I just have not finished the app. coding. to a point where I can test it from there.

    Anyhow, I appreciate your help. It saved me a lot of time.

    What other steps do I need to take to process this question correctly?

    Thank you.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply