Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Database > SQL Language
Password Reminder
Register
| FAQ | Members List | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #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
Reply With Quote
  #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
Reply With Quote
  #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
Reply With Quote
  #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
Reply With Quote
  #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
Reply With Quote
  #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
Reply With Quote
  #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?
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 05:22 AM.


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