Results 1 to 7 of 7

Thread: Can Select statement be used along with Update statement?

  1. #1
    Junior Member
    Join Date
    Aug 2007
    Answers
    1

    Can Select statement be used along with Update statement?

    Can Select statement be used along with Update statement in an SQL Query?


  2. #2
    Moderator
    Join Date
    Jun 2007
    Answers
    2,074

    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.


  3. #3
    Junior Member
    Join Date
    Dec 2007
    Answers
    12

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


  4. #4
    Junior Member
    Join Date
    Oct 2008
    Answers
    11

    Re: Can Select statement be used along with Update statement?

    Yes , You can use..


  5. #5
    Junior Member
    Join Date
    Jan 2009
    Answers
    2

    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;


  6. #6
    Contributing Member
    Join Date
    Dec 2008
    Answers
    76

    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);


  7. #7
    Expert Member
    Join Date
    Nov 2008
    Answers
    300

    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


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact