Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Need SQL help on updating a table from another table

Need SQL help on updating a table from another table

From: Cecil D'Souza <cdsouza_at_nc.rr.com>
Date: Tue, 10 May 2005 06:48:22 GMT
Message-ID: <WOYfe.27665$Fa.901894@twister.southeast.rr.com>


I created a TEMP table with the following fields.

Study varchar2(20)
patient varcgar2 (10)

site       Varchar 2(10)
T_0      varchar2(5)
T_05    varhchar2(5)
T_4      varchar2(5)
T_6      varhchar2(5)
T_8      varchar2(5)

I am trying to insert records into that table from another table that has the
first three values for the Study, Patient and Site fields but the values of the remaing columns may or may not have a value based on certain criteria of Q_VAL. Ex. Create table TEMP as

      select study,
               patient
               site
               IMTime
               ' ', ' ', ' ', ' '
      from  Received_data
      where Q_VAL in (11, 14, 15);

The table is created and I get 100 records with the value of IMTime in T_0 while the other T_'s are null as specified. The table received_data has duplicate values for
the columns Study, Patient, Site

Now I want to insert the value of field IMTime into column T_05 of table TEMP
from table received_data when Q_VAL in(13,17,20) Then I want to insert the value of field IMTime into column T_4 of table TEMP
from table received_data when Q_VAL in(16,18,21)

When I try to INSERT the value of field IMTime into T_05 of the TEMP table based on another criteria as in WHERE Q_VAL in (13, 17, 20), it creates ANOTHER 100 records in the TEMP table with all the columns Study, patient, site, ' ', IMTime, ' ', ' ', ' '

I then tried to used the UPDATE clause but it gives me an error saying subquery returns more than 1 row.

I am not in the office now. Will this code below work? UPDATE TABLE TEMP b
set b.T_05 = (select a.IMtime from received_data a

                   where a.study = b.study
                     and   a.patient = b.patient
                    and    a.site = b.site
                    and Q_VAL in (13,17,20)


Thanks for your help.

Cecil Received on Tue May 10 2005 - 01:48:22 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US