Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 UPDATE and Inner Joins

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-02-25 : 08:28:26
Bert writes "I have two tables in MS SQL, where I want to set a boolean value in the first table when a record matches in the second.
I am using an inner join, but the problem is that if two rows exist in the first table which meet the ON conditions, then both rows are set in the first table.
Unfortunately I need a method of only setting the same number of rows in both tables.

My SELECT statement is:

UPDATE table1 SET flag='Y from table1 INNER JOIN table2 ON (table1.a = table2.a) and (table1.b = table2.b)

For example if I have a row in table2 that matches 2 rows in table1 - I only want to set 1 row. Likewise if I have 2 rows in table2 and 3 rows in table1, I only want to set 2 rows in table1. Is it possible to do this?"

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-02-25 : 08:44:46
set rowcount 1
UPDATE table1 SET flag='Y from table1 INNER JOIN table2 ON (table1.a = table2.a) and (table1.b = table2.b)
set rowcount 0


Go with the flow & have fun! Else fight the flow
Go to Top of Page
   

- Advertisement -