[SQL] delete where not in another table

2013-07-09 Thread Campbell, Lance
If I have two tables, T1 and T2, such that both have the same primary key of "user_id". What is the SQL I would use to delete all rows from T1 that are not in T2? This is one way to write the SQL but it is really inefficient: DELETE FROM T1 WHERE T1.user_id NOT IN (SELECT user_id FROM T2 WHERE

Re: [SQL] delete where not in another table

2013-07-09 Thread Igor Neyman
From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@postgresql.org] On Behalf Of Campbell, Lance Sent: Tuesday, July 09, 2013 3:25 PM To: pgsql-sql@postgresql.org Subject: [SQL] delete where not in another table   DELETE FROM T1 WHERE T1.user_id NOT IN (SELECT user_id FROM T2 WHERE T2.