Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
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
 
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?
 
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.
 
Old February 10th, 2011, 01:29 PM
Friend of Wrox
 
Join Date: Jul 2003
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.





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





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