Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
| Search | Today's Posts | Mark Forums Read
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old June 18th, 2003, 07:30 AM
Registered User
 
Join Date: Jun 2003
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Update inner join question

Hi all

I've recently been moving apps to SQL2k from Access 2k

In access I could do

update table1 inner join table2 on table1.key=table2.key set table1.column1=table2.column1

Which doesn't work in SQL. The help files make some reference to update and joins but I can't get this to play ball.

Any clues please?

Regards
Graham
  #2 (permalink)  
Old June 18th, 2003, 07:32 AM
Authorized User
 
Join Date: Jun 2003
Location: Edinburgh, , United Kingdom.
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try this

update table1
   set table1.column1=table2.column1
  from table2 inner join table2 on table1.key=table2.key

Cheers

Nickie
  #3 (permalink)  
Old June 18th, 2003, 08:05 AM
Registered User
 
Join Date: Jun 2003
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Nickie

That gives me an error about needing to use correllation to distinguish the columns.

The actual line is: -
update allocations
set allocations.driver_name=drivers.driver_name
from drivers inner join drivers on allocations.driver_record_number=drivers.record_nu mber
  #4 (permalink)  
Old June 18th, 2003, 09:05 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Hudson, MA, USA.
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

Quote:
quote:Originally posted by Graham
 Thanks Nickie

That gives me an error about needing to use correllation to distinguish the columns.

The actual line is: -
update allocations
set allocations.driver_name=drivers.driver_name
from drivers inner join drivers on allocations.driver_record_number=drivers.record_nu mber
Without knowing your table structure I'm guessing your JOIN ought to read:
Code:
FROM drivers INNER JOIN allocations ON
   allocations.driver_record_number=drivers.record_number
Jeff Mason
Custom Apps, Inc.
www.custom-apps.com
  #5 (permalink)  
Old June 18th, 2003, 10:02 AM
Registered User
 
Join Date: Jun 2003
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry Jeff

That is what it does say, all down to satellite delay between brain and keyboard!

Regards
Graham
  #6 (permalink)  
Old June 18th, 2003, 10:14 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Hudson, MA, USA.
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

So you say the offending code is:
Code:
update allocations 
set allocations.driver_name=drivers.driver_name
from drivers inner join allocations on allocations.driver_record_number=drivers.record_number
And this is generating an error?

This query looks fine to me. Post the table defs, because something else is going on here...

Jeff Mason
Custom Apps, Inc.
www.custom-apps.com
  #7 (permalink)  
Old January 22nd, 2011, 11:55 AM
Registered User
 
Join Date: Jan 2011
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Question Update with multi row subquery

id mgrid depno
1 null 10
2 null 20
3 1 20
4 2 10
5 3 10

explation: in above table id - "1" has depno 10 and id - "3" has depno 20 but "1" is manager of "3". so id - "3" should have depno 10.
similarly id - "4" should have depno 20.
similarly we need to check this for id - "5".

i want to do this with update query. please let me know what should be query like?


Similar Threads
Thread Thread Starter Forum Replies Last Post
Join Question designdawg Access 3 December 18th, 2007 12:43 PM
Update Query using inner join with a linked table ceekay Access 3 June 8th, 2007 12:35 PM
UPDATE JOIN crmpicco MySQL 0 August 23rd, 2005 06:55 AM
Update and Inner Join Question - Access 97 snoopy92211 Access VBA 1 February 28th, 2005 04:30 PM
UPDATE & JOIN (and WHERE) pete_m SQL Server 2000 2 September 28th, 2004 05:19 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.