Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sqlite insert into table select * from

I need to move data from one table to another in my Android app

I would like to use the following sql:

insert into MYTABLE2 select id, STATUS risposta, DATETIME('now') data_ins from  MYTABLE 2 

Unfortunately in table MYTABLE2 there is an _ID column AUTOINCREMENT. What could I do?

Thanks.

EDIT: this is my MYTABLE2 the, the table I would like to populate with data from another table:

CREATE TABLE "ANSWERS" ("_id" INTEGER PRIMARY KEY  AUTOINCREMENT  NOT NULL , "ID_QUESTION" INTEGER,"DATE_INS" DATETIME DEFAULT  (CURRENT_DATE) , "ANSWER" INTEGER) 
like image 627
Gyonder Avatar asked May 30 '13 14:05

Gyonder


People also ask

How manually insert data in SQLite database?

If you want to inset the data manually(fully graphical) do the following: Go to the DDMS perspective. File explorer (tab-menu) Locate your db (/data/data/com.

Can insert be used with SELECT?

You can use a select-statement within an INSERT statement to insert zero, one, or more rows into a table from the result table of the select-statement. The select-statement embedded in the INSERT statement is no different from the select-statement you use to retrieve data.


1 Answers

explicitly specify the column name in the INSERT clause,

INSERT INTO destinationTable (risposta, data_ins) SELECT STATUS risposta, DATETIME('now') data_ins  FROM   sourceTable 
like image 99
John Woo Avatar answered Oct 11 '22 12:10

John Woo