X-Original-To: pgsql-sql@postgresql.org Received: from esc.esc1.com (dpc6682143102.direcpc.com [66.82.143.102]) by postgresql.org (Postfix) with ESMTP id 73893476022 for ; Tue, 11 Mar 2003 15:48:18 -0500 (EST) Received: from esc1.com (IDENT:terry@localhost [127.0.0.1]) by esc.esc1.com (8.11.0/8.11.0) with ESMTP id h2BKkEU11395; Tue, 11 Mar 2003 15:46:14 -0500 Message-ID: <3E6E4B16.4060700@esc1.com> Date: Tue, 11 Mar 2003 15:46:14 -0500 From: Terry Lee Tucker Organization: Enhanced Solutions Computing User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.2) Gecko/20021120 Netscape/7.01 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Terry Lee Tucker Cc: pgsql-sql@postgresql.org Subject: Re: Novice needs help References: <3E6E2139.5060903@esc1.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Archive-Number: 200303/265 X-Sequence-Number: 12305 I answered my own question. Yes, it can be done like this: SELECT code, name, city, country, province FROM cust WHERE (country, province) NOT IN (SELECT country, code FROM province); The query returned two cust records that had bogus province codes in them. Very cool :o) Terry Lee Tucker wrote: > I have loaded over 29,000 customer records into a database. I'm trying > to apply a referential foreign key that validates the country code and > the province code in another table. It won't work because somewhere in > that 29,000 records there is a province code or country code that > doesn't match. Is there a way to use a select statement to find out > which customer records has the invalid data? Here is the partial table > layout: > > cust province > -------- ------- > country ===> country > province ===> code > > Thanks in advance... > -- Sparta, NC 28675 USA 336.372.6812 http://www.esc1.com