sqlite - Delete subtable from a table, SQL -


what clever way delete tuples table1, in second table, if second table not part of initial database, result of big query?

table1           *this table result of query -------------    ------------- | id1 | id2 |    | id1 | id2 | -------------    ------------- | 1      2  |    | 5      6  | | 3      4  |    | 1      2  | | 5      6  |    | 11     12 | | 7      8  |    ------------- | 9      10 |     | 11     12 | | 13     14 | ------------- 

i came with

delete table1 id1 in (select id1 (         long query second table))   , id2 in (select id2 (the same long query second table)); 

it works, feel i'm doing way wrong, , not keeping query dry.

and way suggest work same if table1 had additional column, example "somecol"?

imo, can use exists statement this:

delete table1 exists (     select 1     (<your long query>) dt     table1.id1 = dt.id1       , table1.id2 = dt.id2); 

[sql fiddle sample]


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -