Update a record through EXISTS

  • Hi,

    I want to update a record, if the record count of another table equal to 1. How can i achieve this.

    Is it possible with EXISTS command.

    ---

  • yes you can. if record count is only criteria then this will work.

    Update table1 set col1 = value

    where exists (select * From table2)

    "Keep Trying"

  • Chirag (11/4/2008)


    yes you can. if record count is only criteria then this will work.

    Update table1 set col1 = value

    where exists (select * From table2)

    Thanks for your quick reply.

    If i use exists in where clause then what about my performance in this?

    Moreover i want to compare number of count which return in this subquery with 1.

    ---

  • Hi

    Performance will mostly depend on the number of rows you are going to update rather than the exists clause.

    So if you want to update only if the record count is one

    update table1 set col1 = somevalue

    WHERE Exists (select count(*) from table2 having count(*) = 1)

    "Keep Trying"

  • I want to update a record, if the record count of another table equal to 1. How can i achieve this.

    Is it possible with EXISTS command.

    Did you want to update when the record count of the *entire table* was equal to 1(as in the example above), or when some criteria resulted in a count of 1. The above query will update your entire table1 with somevalue if table2 exists and has exactly 1 row in it. That is what you asked for, but it seems to me you may have wanted something different.

    This whole thing is pretty open ended. If the above query does not give the expected results, please explain exactly what you're looking for a little better. It would probably help explain if you would post the query you're trying to write, and if possible, supply a small amount of sample data. (A link to a post on how to do this is in my signature)

    Seth Phelabaum


    Consistency is only a virtue if you're not a screwup. 😉

    Links: How to Post Sample Data[/url] :: Running Totals[/url] :: Tally Table[/url] :: Cross Tabs/Pivots[/url] :: String Concatenation[/url]

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

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