0

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.

1 Answer 1

1

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'
  ;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.