1

i'm trying to make sqlite query that can insert multiple values , here's my query that i try :

    insert into table1(idy_table1,idx_table1) 
    values ('1',                               //specified value insert to idy_table1                               
    (select id_table2 from table2))            //insert value from select id_table2

i'm having some trouble, it just only insert one value,

and my question is how to make a proper query? so i can make it work.

1 Answer 1

2

The VALUES clause always adds one row. (Except when you're using multiple tuples, but this does not work with queries.)

The easiest way to add multiple rows from a query is to use the SELECT form of the INSERT statement:

INSERT INTO Table1(idy_table1, idx_table1)
SELECT '1', id_table2 FROM table2;
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.