Skip site navigation (1) Skip section navigation (2)

Re: nested query

From: "Oliver Elphick" <olly(at)lfix(dot)co(dot)uk>
To: Mustapha Amrani <ma10024(at)newton(dot)cam(dot)ac(dot)uk>
Cc: pgsql-docs(at)postgresql(dot)org
Subject: Re: nested query
Date: 2001-01-05 15:01:35
Message-ID: 200101051501.f05F1ZH32112@linda.lfix.co.uk (view raw or flat)
Thread:
Lists: pgsql-docs
Mustapha Amrani wrote:
  >I have two linked tables Table1 and Table2. I have deleted some rows in tabl
      >e1
  >Now I need two delete the rows in table2 that correspond to the rows
  >deleted in table1. The two table are linked by field id.
  >I tried the following but with no success:
  >delete * from table2 where not exists (select * from table1 where
  >table2.id=id);

How about:

DELETE FROM table2 WHERE id NOT IN (select id FROM table1);

-- 
Oliver Elphick                                Oliver(dot)Elphick(at)lfix(dot)co(dot)uk
Isle of Wight                              http://www.lfix.co.uk/oliver
PGP: 1024R/32B8FAA1: 97 EA 1D 47 72 3F 28 47  6B 7E 39 CC 56 E4 C1 47
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839  932A 614D 4C34 3E1D 0C1C
                 ========================================
     "And thou shalt love the LORD thy God with all thine 
      heart, and with all thy soul, and with all thy might."
                 Deuteronomy 6:5 



pgsql-docs by date

Next:From: Robert B. EasterDate: 2001-01-05 20:19:51
Subject: compiling the man-pages
Previous:From: Mustapha AmraniDate: 2001-01-05 14:04:06
Subject: nested query

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group