on 2016 Mar 01 3:23 PM
Hey,
I have a table MEASUREMENT (DATE, VALUE) and one EVENT (EVENT-ID, DATE), now I want to select the value of a measurement one day before an event into a separate table MEASUREMENT_BEFORE_EVENT. Therefore I using following SQL statement.
INSERT INTO "MEASUREMENT_BEFORE_EVENT" ("VALUE","DATE")
SELECT "VALUE","DATE" FROM "MEASUREMENT"
WHERE "DATE" IN (SELECT ADD_DAYS("EVENT-DATE",-1) FROM "EVENT" ORDER BY "EVENT_DATE" ASC);
Now I would like to extend this and insert also the EVENT-ID into MEASUREMENT_BEFORE_EVENT
INSERT INTO "MEASUREMENT_BEFORE_EVENT" ("VALUE","DATE","EVENT-ID")
SELECT "VALUE","DATE" (SELECT "DATE" FROM "EVENT") FROM "MEASUREMENT"
WHERE "DATE" IN (SELECT ADD_DAYS("EVENT-DATE",-1) FROM "EVENT" ORDER BY "EVENT_DATE" ASC);
When I do like this then I get
ERROR: single-row query returns more than one row
Is there a possibility to do that?
Request clarification before answering.
Matthias,
the issue is on your inner query select "DATE" from "EVENT" you will need to do an inner join between your EVENT table and your MEASUREMENT table so that you can get multiple records in your select statement. once you get your select statement working then you can perform your insert operation.
hope this helps
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 15 | |
| 9 | |
| 6 | |
| 4 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.