1

I have next code:

INSERT INTO some_table (id, value1, value2, value3)
      VALUES (
        (SELECT id FROM user_table WHERE some_column = 'data'), 
        (SELECT value1, value2 FROM event_table WHERE type = 'some_type'),
        value3
      )

And I am getting next error: subquery must return only one column This error related to second 'select', but I don't understand why. I should return two values and it is ok.

1 Answer 1

3

Use insert . . . select`:

INSERT INTO some_table (id, value1, value2, value3)
    SELECT ut.id, et.value1, et.value2, <value3>
    FROM user_table ut JOIN
         event_table et
         ON ut.some_column = 'data' AND et.type = 'some_type';

Notes:

  • It is not clear where value3 comes from. I assume it is a constant of some sort.
  • This version will not return any rows if the conditions do not match in either table. I assume this is a feature and not a bug.
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.