November 4, 2008 at 2:05 am
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.
---
November 4, 2008 at 2:16 am
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"
November 4, 2008 at 2:24 am
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.
---
November 4, 2008 at 10:49 pm
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"
November 5, 2008 at 5:51 am
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)
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply