Prepare for your Next Interview
This is a discussion on How to update more than one row with a different value within the SQL forums, part of the Databases category; Question asked by visitor kamana How to update more than one row with a different value with in a single column by a single update query....
|
|||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
|
|||
|
How to update more than one row with a different value
Question asked by visitor kamana
How to update more than one row with a different value with in a single column by a single update query. |
| Sponsored Links |
|
|||
|
Re: How to update more than one row with a different value
One possible way could be with the use of CASE statement where the column that needs to be updated depends on some other column value.
A small example: -- Create the table CREATE TABLE t_bh ( a NUMBER, b VARCHAR2(100)) -- Insert 3 values. -- The column b in all the 3 records has 'ABC'. INSERT INTO t_bh VALUES( 1, 'ABC') INSERT INTO t_bh VALUES( 2, 'ABC') INSERT INTO t_bh VALUES( 3, 'ABC') UPDATE t_bh SET b = CASE WHEN a = 1 THEN 'ABC' WHEN a = 2 THEN 'DEF' WHEN a = 3 THEN 'GHI' END ; Now U have 3 different values updated for b column with a single query. Not sure if this helps for your requirement. Thanks. |
|
|||
|
Re: How to update more than one row with a different value
not sure but try below one
considering emp s reference table,if deptno of type varchar update emp set deptno=decode(deptno,10,'ten',20,'twenty','thirty'); |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How can IGRP and OSPF Update routing table? | Geek_Guest | Networking | 1 | 07-19-2007 09:02 PM |
| How to rectify this using a single update query | pjitu1969 | SQL | 2 | 03-18-2007 03:14 AM |
| Update strategy transformation | JobHelper | Data Warehousing | 1 | 02-03-2007 04:17 AM |
| Kindly update me the Limitations | christia | Unix/Linux | 1 | 09-13-2006 12:33 PM |
| Kindly update me the use of this Program | Remasri | Unix/Linux | 1 | 08-11-2006 05:14 AM |