INSERT and SELECT statements [message #674967] |
Tue, 26 February 2019 08:53 |
|
philipsampson
Messages: 1 Registered: February 2019
|
Junior Member |
|
|
Hi,
I'm trying to create a query to insert multiple entries into a table(TABLE B) based on a SELECT query on another table(TABLE A), but cant get the syntax....would be grateful for any input.
The tables can be simplified as:
TABLE_A {user_id, last_login_date,...}
TABLE_B {sequential_id, field_1, field_2, ...}
I put together the following, which ceases to work as soon as the 'SELECT FROM TABLE A' statement returns more than one row. I've read the documentation around the topic, so have an outline understanding of why it comprises an error condition, but am not sure how to resolve.
INSERT INTO TABLE_B
( sequential_id,
field_1,
field_2 )
VALUES
( (SELECT MAX(sequential_id) + 1 FROM TABLE_B),
(SELECT user_id FROM TABLE_A where last_login_date > 'some date' AND last_login_date < 'some other date'),
'some text' );
I'd appreciate any input/suggestions...?
Thanks in advance,
Phil
|
|
|
|