Reputation: 595
I am trying to run a query in which a particular column value is a foreign key.
INSERT INTO tbl_test(group_id, test_name, test_code) VALUES (SELECT group_id FROM tbl_group
where group_code = '6868' , 'test', '123');
This is my query. On executing this query i'm getting an error as
ERROR: syntax error at or near "SELECT"
LINE 1: ... tbl_test(group_id, test_name, test_code) VALUES (SELECT group
I am not sure where i am doing wrong. Please help me on this.
Upvotes: 0
Views: 52
Reputation: 44250
You don't need the values()
, you can just add the literals to the select's column list, like:
INSERT INTO tbl_test(group_id, test_name, test_code)
SELECT group_id , 'test', '123'
FROM tbl_group
WHERE group_code = '6868'
;
Upvotes: 1