Wesley
Wesley

Reputation: 412

Why won't this sql update query work?

I have a table that has 5,000(table1) lines in it. Currently, 3,000 of them are filled up with data. The remaining values are currently null. In a separate table(table2), I have the remaining 2,000 rows of data. I am simply trying to take the values in table2 and put them in table1, but this statement isn't working:

Update table1
  Set field1 = (Select field1 
                  From table2 
                 Where table1.id = table2.id) 
Where Exists(Select field1 
               From table2 
              Where table1.id = table2.id)

It looks like this should be working, but I am getting an error from Base, the db program I am using that just says error Near " ": syntax error...any help?? Thanks!

Upvotes: 2

Views: 372

Answers (2)

user334899
user334899

Reputation:

You could try doing it with a join. I'm used to doing it in T-SQL but I believe the syntax will be the same or pretty similar.

Update Table1
JOIN Table2 ON Table1.id = Table2.id
SET Table1.value = Table2.value

Upvotes: 2

Chad Birch
Chad Birch

Reputation: 74528

Try putting a space between Exists and (Select.

Upvotes: 1

Related Questions