How to copy data from one table to another table with where condition

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • san1014
    New Member
    • Jul 2007
    • 37

    How to copy data from one table to another table with where condition

    Hi
    I have a table, that describes

    SQL> desc time_m_details
    Name Null? Type
    ----------------------------------------- -------- ------
    STUDENT_ID not null VARCHAR2(25)
    SCENARIO_ID not null VARCHAR2(25)
    TIME_ID not null VARCHAR2(25)
    TIME_VALUE VARCHAR2(25)

    In that table one student_id contains many scenario_id's.
    student_id(108) contain scenario_id's(1 5,18,19,6) and
    student_id(1) contain scenario_id's(2 22,223,234,257, 258) etc............ .

    I want to copy the data from scenario_id in one student-id to scenario_id in another student_id

    Like student-id(108) and scenario_id(15) to student_id (1) and scenario_id(258 )

    I have written like this
    SQL> insert into time_m_details( select time_id,time_va lue from time_m_details where student_id='108 ' and scenario_id='15 ') where student_id='1' and scenario_id='25 8';

    Any help?

    Thank You
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    You cant use WHERE in insert into statment . U need to update for that.

    If you want to insert, remove the where clause and also specify the field names.

    Comment

    • amitpatel66
      Recognized Expert Top Contributor
      • Mar 2007
      • 2358

      #3
      Originally posted by san1014
      Hi
      I have a table, that describes

      SQL> desc time_m_details
      Name Null? Type
      ----------------------------------------- -------- ------
      STUDENT_ID not null VARCHAR2(25)
      SCENARIO_ID not null VARCHAR2(25)
      TIME_ID not null VARCHAR2(25)
      TIME_VALUE VARCHAR2(25)

      In that table one student_id contains many scenario_id's.
      student_id(108) contain scenario_id's(1 5,18,19,6) and
      student_id(1) contain scenario_id's(2 22,223,234,257, 258) etc............ .

      I want to copy the data from scenario_id in one student-id to scenario_id in another student_id

      Like student-id(108) and scenario_id(15) to student_id (1) and scenario_id(258 )

      I have written like this
      SQL> insert into time_m_details( select time_id,time_va lue from time_m_details where student_id='108 ' and scenario_id='15 ') where student_id='1' and scenario_id='25 8';

      Any help?

      Thank You
      Try this:

      I think you need to do an update as I could see from your insert statement that you are selecting student id 1 and 258.

      I am not clear with your requirement?
      What is yur insert doing? did you try that??

      Comment

      Working...