3

I table 1 contains:

    |col1|
    | 1  |
    | 2  |
    | 1  |
    | 3  |
    | 1  |
    | 2  |
    | 4  |
    | 2  |
    | 3  |
    | 1  |

and I have another table has a column name val, and my code is

INSERT INTO table2(value) VALUES ((select distinct col1 from table1))

I got the #1242 - Subquery returns more than 1 row.
How can I get multiple rows insert into my table2 ?

1

2 Answers 2

6

You don't need the values statement when using insert . . . select:

INSERT INTO table2(value)
    select distinct col1
    from table1;
Sign up to request clarification or add additional context in comments.

Comments

4
INSERT INTO table2(value)
select distinct col1 
from table1

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.