SQLite Forum

adding record if it doesn't already exist
Login
Assuming that you have a unique index on table1.email, then why not use this more simple command:

```
INSERT OR IGNORE INTO table1(email) VALUES ('test@domain.com');
```

Of course, if you either have no useable index then you can use a longer more inefficient method such as:

```
INSERT INTO table1 (email) 
     SELECT email 
       FROM (
             SELECT 'test@domain.com' AS email
            ) AS o
      WHERE NOT EXISTS (
                        SELECT *
                          FROM table1
                         WHERE email == o.email
                       );
```

The former is much shorter and staightforward while the latter is much longer and slower, but is standard SQL that should work unchanged on all SQL platforms since about 1985.