sqlite - Deleting rows not existing in another table with composite primary key's -


i'm using sqlite , trying move old rows table students students_old, , copy new rows students_import.

the problem have multiple primary keys this:

create table "students" ( `lastname`  text not null, `firstname` text not null, `borndate`  text not null, `class` text not null, `photo` text, `validuntil`    char(10), primary key(lastname,firstname,borndate)) 

all tables have structure (except students_import that's missing photo , validuntil).

so far have managed copy old rows this:

insert students_old  select distinct a.lastname, a.firstname, a.borndate, a.class, a.photo, a.validuntil students left join students_import b on a.lastname =b.lastname , a.firstname=b.firstname , a.borndate=b.borndate b.lastname null; 

and add new rows this:

insert students  select distinct a.lastname, a.firstname, a.borndate, a.class, "", ""  students_import left join students b on a.lastname =b.lastname , a.firstname=b.firstname , a.borndate=b.borndate b.lastname null 

but can't figure out how delete old rows in students (that don't exist in students_import).

i have tried few variants of this:

delete students (lastname, firstname, borndate) in (select distinct a.lastname, a.firstname, a.borndate, a.class, a.photo, a.validuntil  students left join students_import b on a.lastname =b.lastname , a.firstname=b.firstname , a.borndate=b.borndate b.lastname null); 

but syntax error or can't use on multiple rows.

i appreciate help!

in not work multiple columns.

to find rows not exist in table, use not exists correlated subquery:

delete students not exists (select 1                   students_import                   students_import.lastname  = students.lastname                     , students_import.firstname = students.firstname                     , students_import.borndate  = students.borndate); 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -