Geeks Talk

Prepare for your Next Interview




How to update more than one row with a different value

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....


Go Back   Geeks Talk > Databases > SQL

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 04-16-2007
Expert Member
 
Join Date: Feb 2007
Posts: 1,279
Thanks: 0
Thanked 164 Times in 138 Posts
Geek_Guest is on a distinguished roadGeek_Guest is on a distinguished road
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.
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-19-2007
Junior Member
 
Join Date: Apr 2007
Location: Bangalore
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
bhavya_gs is on a distinguished road
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.
Reply With Quote
  #3 (permalink)  
Old 04-19-2007
Junior Member
 
Join Date: Mar 2007
Location: chennai
Posts: 18
Thanks: 15
Thanked 0 Times in 0 Posts
dhanasweet is on a distinguished road
Re: How to update more than one row with a different value

using like we can update more than one row,with different value in column
Reply With Quote
  #4 (permalink)  
Old 04-23-2007
Junior Member
 
Join Date: Feb 2007
Location: Bangalore
Posts: 17
Thanks: 0
Thanked 1 Time in 1 Post
jbanx is on a distinguished road
Re: How to update more than one row with a different value

Certainly using "case" we can update a row with different values !!!
Reply With Quote
  #5 (permalink)  
Old 01-24-2008
Junior Member
 
Join Date: Jan 2008
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
chaitueeturi is on a distinguished road
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');
Reply With Quote
  #6 (permalink)  
Old 02-14-2008
Junior Member
 
Join Date: Jan 2008
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
chaitueeturi is on a distinguished road
Re: How to update more than one row with a different value

try below one
considering emp s reference table,if deptno of type varchar

update emp
set deptno=decode(deptno,10,20,20,30,30);
Reply With Quote
Reply

  Geeks Talk > Databases > SQL


Thread Tools
Display Modes


Similar Threads

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


All times are GMT -4. The time now is 12:30 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Copyright © 2008 GeekInterview.com. All Rights Reserved