I have two tables that store value as VARCHAR.
I’m populating table and I want just insert values in one of tables if they are not exist in other table.
Something like:
INSERT IF IS EMPTY(SELECT * FROM t1 where v='test') INTO t2 (v) VALUES ('test')
How Can I do that?
You need to use some type of
INSERT...SELECTquery.Update (after clarification): For example, here is how to insert a row in
t2if a corresponding row do not already exist int1:To insert multiple rows with the same query, I ‘m afraid there is nothing better than
Original answer
For example, this will take
other_columnfrom all rows fromtable1that satisfy theWHEREclause and insert rows intotable2with the values used ascolumn_name. It will ignore duplicate key errors.