Reputation: 391
I am trying to create a row in an existing table which consists of current timestamp, and some other data from other table.
What would be a correct syntax to achieve it? Below is a pseudo code for what I am trying to achieve.
INSERT INTO logTable
VALUES( currentTimeStamp, select data1, data2, data3 FROM datatable WHERE data1 = 123);
Upvotes: 1
Views: 1041
Reputation: 1712
INSERT INTO logTable (column1, column2, column3,column4)
select CURRENT_TIMESTAMP,data1, data2, data3 FROM datatable WHERE data1 = 123
You can use something else instead of CURRENT_TIMESTAMP, but make sure column types matches.
Upvotes: 2
Reputation: 1269873
You cannot mix insert . . . values
and insert . . . select
. Just use:
INSERT INTO logTable
select currentTimeStamp, data1, data2, data3
FROM datatable
WHERE data1 = 123;
Or, better yet, set up the column to have a default value of the current time stamp so it gets set automatically.
Upvotes: 2