Geeks Talk

Prepare for your Next Interview


Welcome to the Geeks Talk forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

Can Select statement be used along with Update statement?

This is a discussion on Can Select statement be used along with Update statement? within the SQL forums, part of the Databases category; Can Select statement be used along with Update statement in an SQL Query?...

Go Back   Geeks Talk > Databases > SQL
Register Blogs FAQ Tag Cloud Calendar Mark Forums Read
  #1 (permalink)  
Old 08-23-2007
Junior Member
 
Join Date: Aug 2007
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
pankit is on a distinguished road
Can Select statement be used along with Update statement?

Can Select statement be used along with Update statement in an SQL Query?
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-23-2007
Moderator
 
Join Date: Jun 2007
Location: Bangalore,India
Posts: 1,933
Thanks: 10
Thanked 179 Times in 149 Posts
debasisdas has a spectacular aura aboutdebasisdas has a spectacular aura about
Re: Can Select statement be used along with Update statement?

Yes that can be used ,
You can update one field by selecting from another field / table.
Reply With Quote
  #3 (permalink)  
Old 01-10-2008
Junior Member
 
Join Date: Dec 2007
Location: india
Posts: 12
Thanks: 0
Thanked 1 Time in 1 Post
nitin_padwal is on a distinguished road
Re: Can Select statement be used along with Update statement?

following query will help you to update multiple columns at once

update tblOuter
set colOuter1 = a.colInner1,
colOuter2 = a.colInner2,
colOuter3 = a.colInner3,
from ( select colInner1,colInner2,colInner3
from tblInner
where conditions on tblInner columns
) as a
where condition on tblOuter's columns

be careful with your where conditions..........
Reply With Quote
The Following User Says Thank You to nitin_padwal For This Useful Post:
  #4 (permalink)  
Old 12-06-2008
Junior Member
 
Join Date: Oct 2008
Location: a
Posts: 22
Thanks: 11
Thanked 0 Times in 0 Posts
nathsambu is on a distinguished road
Re: Can Select statement be used along with Update statement?

Yes , You can use..
Reply With Quote
  #5 (permalink)  
Old 01-04-2009
Junior Member
 
Join Date: Jan 2009
Location: New Delhi, INDIA
Posts: 2
Thanks: 0
Thanked 1 Time in 1 Post
rajgupta7666 is on a distinguished road
Re: Can Select statement be used along with Update statement?

yes you can use select statment in update
Example:-
update employees
set salary=10000
where employee_id=select employee_id from employees where last_name='king' and department_id=10;
Reply With Quote
The Following User Says Thank You to rajgupta7666 For This Useful Post:
  #6 (permalink)  
Old 01-05-2009
Contributing Member
 
Join Date: Dec 2008
Location: bangalore
Posts: 76
Thanks: 0
Thanked 18 Times in 18 Posts
ecearund is on a distinguished road
Re: Can Select statement be used along with Update statement?

Yes you can...
Here some examples for u...

1)
UPDATE Table1
SET Table1(col1) = (SELECT Table2(col1)
FROM Table2
WHERE some condition);


2)
UPDATE Table1
SET Table1(col1)='xxxxxxxxxx'
WHERE Table1(col2)=
(
SELECT ab.Table2(col2)
FROM Table1 a, Table2 ab
WHERE a.Table1(col3)=ab.Table2(col3)
);

3)
UPDATE Table1
SET Table1(col1) = ( SELECT Table2.col1
FROM Table2
WHERE Table2.col2 = Table1.col2)
WHERE EXISTS
( SELECT Table2.col1
FROM Table2
WHERE Table2.col2 = Table1.col2);
Reply With Quote
  #7 (permalink)  
Old 01-15-2009
Expert Member
 
Join Date: Nov 2008
Location: Chennai
Posts: 303
Thanks: 1
Thanked 37 Times in 32 Posts
amitpatel66 is on a distinguished road
Re: Can Select statement be used along with Update statement?

Yes you can use SELECT statement as a subquery for updating a particular column in UPDATE statement
Reply With Quote
Reply

  Geeks Talk > Databases > SQL

Thread Tools
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 On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
Is this a correct statement anoop4real C and C++ 13 05-22-2008 06:22 AM
Why we have to close connection, statement, prepared statement Geek_Guest Java 8 02-27-2008 06:09 AM
I just want to commit my second Insert statement Geek_Guest Oracle 1 07-21-2007 05:48 AM
How many Case statments can i use in Switch Statement Geek_Guest C and C++ 9 07-03-2007 04:56 AM
Rules for COPY statement norman MainFrame 1 08-14-2006 04:11 AM


All times are GMT -4. The time now is 03:55 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.3.1
Copyright © 2005 - 2010 GeekInterview.com. All Rights Reserved