Easy Table Update Question
Posted on 2006-06-13
I am using MS SQL 2000 and I actually had a question about the below piece of SQL code. I guess I am having trouble grasping how it works (and whether it does what I intend to do).
update Table A
set someColumn = 'Yes'
where id in (select id from Table B)
and date in (select date from Table B)
and someColumn is null
What I really want to do is to set someColumn to 'Yes' only when the id and date on the same row match the id and date from Table B also on a single row. Each id could occur multiple times in either table with different dates. However, I am worried that SQL Server might pick an id and a date from separate rows in Table B and update someColumn to 'Yes' in Table A since that combination happened to fall on one row. Is that what's happening here?
My apologies if the question above was unclear in any way. I'd be happy to explain in greater detail if necessary. Thanks for all your help!