What’s wrong in this code:
INSERT INTO main.table_1
(SELECT *
FROM TempDatabase.table_1
WHERE TempDatabase.table_1.ID != "5855CA0F8E23")
I made a condition on ID to prevent duplicates (and also because I applied a constrain on main.table_1). However, as I run in SQLiteManager, I got a syntax error “near SELECT”.
If I removed the brackets, still I got another error due to violating constrain on main.table_1 (as If the WHERE condition is totally ignored!)
What am I doing wrong over here!
The correct syntax is your second try, without the parentheses. (Parentheses are used to define the column names that you will insert into.)
You are getting a constraint violation because, despite what you think, inserting your temp data into your main database is actually violating some constraint on your main db table, even if you exclude the one record that has the id
5855CA0F8E23. Check your constraints.