0

I want to copy two columns from table 1 into table 2, filling another two columns in table 2 with fixed strings. Here's what I've attempted:

table1 has columns: name, age, child, adult
table2 has columns: name, param, xvalue, yvalue

INSERT INTO table2 (name, param, xvalue, yvalue) 
  VALUES ('John', 'age', 
      SELECT child FROM table1 WHERE name='John',
      SELECT adult FROM table1 WHERE name='John');

But it gives a missing expression error.

The result should have table2 name column be John for all rows, and likewise the param column should be age for all rows. Table 2 xvalue and yvalue columns should contain the selected data from table 1.

Any idea how to do this?

1 Answer 1

2

Use insert . . . select:

INSERT INTO table2 (name, param, xvalue, yvalue) 
     SELECT 'John', 'age', child, adult
     FROM table1 
     WHERE name = 'John';
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.