DBAsupport.com Forums - Powered by vBulletin
Results 1 to 3 of 3

Thread: insert with select

  1. #1
    Join Date
    Apr 2001
    Posts
    7

    Exclamation

    Hi,
    I have two tables student and student_grades
    student
    =======
    Opm_oid NUMBERm (p.k.)
    NAME VARCHAR(50)

    student_grades
    ==============
    opm_aid NUMBER (p.k.)
    opm_oid NUMBER (f.k.)
    GRADE VARCHAR(5)

    My question is as follows :-
    This is my insert statement for student

    insert into student (Opm_oid, NAME) values
    (10, 'BAKER');

    Now I want to insert student_grades
    in one single sql statement using insert with
    select, I need to find
    the value 'Opm_oid' for BAKER from the student
    table and insert into student_grades along with
    other values.

    Can something like this will work ?


    insert into student_grades (opm_aid, grade,
    opm_oid) values ('3', 'A+', select opm_oid from
    student where name = 'BAKER');

    Please let me know what is the correct way to
    do this, I don't want to use procedures for
    performance issues.

    Thanks.
    Sincerely,
    Viji


  2. #2
    Join Date
    May 2000
    Posts
    58
    insert into student_grades (opm_aid, grade,
    opm_oid)
    select '3', 'A+', opm_oid
    from student
    where name = 'BAKER' ;


  3. #3
    Join Date
    Apr 2001
    Posts
    7

    Smile

    Thanks for your reply,
    it works fine.
    Viji

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width