mssql where not exists code example
Example 1: sqlite insert if not exists
#id column is assumed to be primary key
INSERT INTO destination_table(id,name)
SELECT id, name
FROM source_table s
WHERE NOT EXISTS (
SELECT 1
FROM destination_table d
WHERE d.id = s.id
);
Example 2: not exists mysql
SELECT DISTINCT store_type FROM stores
WHERE NOT EXISTS (SELECT * FROM cities_stores
WHERE cities_stores.store_type = stores.store_type);