Hooked
Hooked

Reputation: 88148

Insert and select from other table and contant value

I'm looking to "mark" entries of my SQLite database. This following command will add new entries from the other_table:

INSERT OR IGNORE INTO landing_table (idx)
SELECT gidx FROM other_table

However, I want to update only the entries that don't exist in landing_table that do exist in other_table to have the value computed set to 1.

INSERT OR IGNORE INTO landing_table idx (idx, computed)
SELECT gidx FROM other_table
AND SET computed=1

Obviously this isn't correct. I would like to do this in a single insert statement rather than an insert and future UPDATE statement.

Upvotes: 0

Views: 58

Answers (1)

Colonel Thirty Two
Colonel Thirty Two

Reputation: 26569

Select a constant value for computed.

INSERT OR IGNORE INTO landing_table idx (idx, computed)
SELECT gidx, 1 FROM other_table

Upvotes: 1

Related Questions