Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id E649964FD91 for ; Sat, 22 Nov 2008 11:47:15 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 31341-09 for ; Sat, 22 Nov 2008 11:47:13 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail14.svc.cra.dublin.eircom.net (mail14.svc.cra.dublin.eircom.net [159.134.118.30]) by mail.postgresql.org (Postfix) with SMTP id C21F964FD71 for ; Sat, 22 Nov 2008 11:47:12 -0400 (AST) Received: (qmail 73344 messnum 2006500 invoked from network[86.46.36.198/unknown]); 22 Nov 2008 15:47:09 -0000 Received: from unknown (HELO ?127.0.0.1?) (86.46.36.198) by mail14.svc.cra.dublin.eircom.net (qp 73344) with SMTP; 22 Nov 2008 15:47:09 -0000 Message-ID: <4928297C.1070805@iol.ie> Date: Sat, 22 Nov 2008 15:47:08 +0000 From: Raymond O'Donnell Reply-To: rod@iol.ie User-Agent: Thunderbird 2.0.0.18 (Windows/20081105) MIME-Version: 1.0 To: Michael Thorsen CC: pgsql-general@postgresql.org Subject: Re: SQL query References: <4c8d33a90811212033x5e88177eo7a026b10336c975b@mail.gmail.com> In-Reply-To: <4c8d33a90811212033x5e88177eo7a026b10336c975b@mail.gmail.com> X-Enigmail-Version: 0.95.7 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Antivirus: avast! (VPS 081121-0, 21/11/2008), Outbound message X-Antivirus-Status: Clean X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200811/1146 X-Sequence-Number: 140864 On 22/11/2008 04:33, Michael Thorsen wrote: > select count(*) > from user_table u, locations l > where u.user_code = l.code > and u.price = l.price > and u.value = l.value; > > The answer to this should be 2, but when I run my query I get 4 (in fact Are you sure that's the query that's being run? I just tried it here, and got 2 - this was using your data above. What do your table definitions look like? - here's what I did: CREATE TABLE user_table ( user_id integer NOT NULL, user_code integer NOT NULL, price numeric(6,2) NOT NULL, "value" numeric(6,2) NOT NULL, CONSTRAINT user_pk PRIMARY KEY (user_id) ) WITH (OIDS=FALSE); CREATE TABLE locations ( id integer NOT NULL, code integer NOT NULL, price numeric(6,2) NOT NULL, "value" numeric(6,2) NOT NULL, CONSTRAINT location_pk PRIMARY KEY (id) ) WITH (OIDS=FALSE); Does this correspond to what you have? Ray. ------------------------------------------------------------------ Raymond O'Donnell, Director of Music, Galway Cathedral, Ireland rod@iol.ie Galway Cathedral Recitals: http://www.galwaycathedral.org/recitals ------------------------------------------------------------------