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 January 22nd, 2011, 12:18 PM
Registered User
 
Join Date: Jan 2011
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Question update with multi row subquery

here is the table for question

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 single update query. please let me know what should be query for this?
Reply With Quote
  #2 (permalink)  
Old January 22nd, 2011, 05:04 PM
Registered User
 
Join Date: Jan 2011
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Question

i need to update this table and correct the wrong entries for id 3 and 4.
should fill depno = 10 for id 3 and depno = 20 for id 4.
query should also check it for id 5 as its value already correct.
Reply With Quote
  #3 (permalink)  
Old February 10th, 2011, 01:29 PM
Friend of Wrox
Points: 2,101, Level: 18
Points: 2,101, Level: 18 Points: 2,101, Level: 18 Points: 2,101, Level: 18
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2003
Location: , , .
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

I think your issue is to prevent the wrong depno's in the database in the first place.

Otherwise, I don't see any usable logic to determine which rows need to get updated.

Something like:

UPDATE [Table] SET depno = 20 WHERE id IN (SELECT id FROM [Table Employee] WHERE [Column 1] IN (id's that need to be updated to 20))

Post the logic and please look at why the wrong depno is getting saved to the table in the first place.
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
multi-multi-multiple Insert with subquery??? jmjyiannis SQL Server 2000 1 May 5th, 2006 02:20 PM
How to Update row to differenct column Jane SQL Language 4 December 12th, 2004 08:55 PM
UPDATE - SUBQUERY WITH FUNCTION ryang Access 2 November 1st, 2004 02:10 PM
Adding a row without using Update command wpyoung2600 ADO.NET 1 August 22nd, 2004 08:26 AM
update my cuurent row melvik ADO.NET 3 July 19th, 2003 11:13 PM



All times are GMT -4. The time now is 10:07 AM.


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