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.
| Author |
Topic |
|
danhayes
Starting Member
3 Posts |
Posted - 2008-06-15 : 18:54:00
|
| Hi,I'm quite new to SQL and wondered if someone could help. I'm pretty good at writing reports but I now need to do an update.Basically i need to update a column in table1 where coulmn 1 in table4 = Y, however to get to table4 I think I need to link to all 4 tables, table4 is the last table. The tables link based on ID'sTried a few things such asUPDATE table1 SET column1 = '' WHERE column1 IN ( SELECT column1 FROM table4 WHERE column1 = Y)Now I need to get to table 4 I need some other wHERE clauses to link them together, just like I would if I were writing a SELECT statement.Any ideas?Many thanks |
|
|
rmiao
Master Smack Fu Yak Hacker
7266 Posts |
Posted - 2008-06-15 : 19:42:52
|
| Can you post table schema? |
 |
|
|
danhayes
Starting Member
3 Posts |
Posted - 2008-06-15 : 23:32:25
|
| I'm affraid I can't do that.In table 1 I want to update a column to null ('') where In table 4 columnx must = YBut then I need to link table 4 to table 3, table 3 to table 2 and so forth, otherwise I can't get to the = Y. So I think I need Where table1.columnx = table2.columnx - When I run the statement it updates all records in my DB, which must mean my statement is wrong. When I write it as a Select query it returns the correct number of records.Cheers |
 |
|
|
danhayes
Starting Member
3 Posts |
Posted - 2008-06-15 : 23:43:08
|
| I have fixed it, many thanks |
 |
|
|
|
|
|