Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TBi8D-0006w3-En for pgsql-sql@postgresql.org; Wed, 12 Sep 2012 08:17:09 +0000 Received: from hub.ringways.co.uk ([77.86.27.30] helo=mail.ringways.co.uk) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TBi8B-0001kY-Jc for pgsql-sql@postgresql.org; Wed, 12 Sep 2012 08:17:08 +0000 Received: from localhost ([127.0.0.1] helo=mail.ringways.co.uk) by mail.ringways.co.uk with esmtp (Exim 4.69) (envelope-from ) id 1TBi86-00011g-61; Wed, 12 Sep 2012 09:17:03 +0100 Received: from eddie.ringways.co.uk ([10.1.1.115] helo=eddie.ringways.co.uk) by mail.ringways.co.uk with ESMTP id q9GxnWRY12343; Wed, 12 Sep 2012 09:16:59 +0100 From: Gary Stainburn Organization: Ringways Garages Ltd To: Samuel Gendler Subject: Re: weird join producing too many rows Date: Wed, 12 Sep 2012 09:17:00 +0100 User-Agent: KMail/1.9.10 Cc: pgsql-sql@postgresql.org References: <201209111542.09386.gary.stainburn@ringways.co.uk> In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <201209120917.00531.gary.stainburn@ringways.co.uk> X-SpamTest-Envelope-From: gary.stainburn@ringways.co.uk X-SpamTest-Info: Profiles 20401 [Mar 31 2011] X-SpamTest-Method: none X-SpamTest-Rate: 0 X-SpamTest-Status: Not detected X-SpamTest-Status-Extended: not_detected X-SpamTest-Version: SMTP-Filter Version 3.0.0 [0285], KAS30/SDK/Release X-Anti-Virus: Kaspersky Mail Gateway, version: 5.6.28/RELEASE, bases: 20110331T110535 #5151353, check: 20120912 clean X-Spam-Score: -51.6 (---------------------------------------------------) X-Spam-Report: Spam detection software, running on the system "ollie.ringways.co.uk", has identified this incoming email as possible spam. The original message has been attached to this so you can view it (if it isn't spam) or label similar future email. If you have any questions, see Gary Stainburn for details. Content preview: Hi, Thanks for this. I did eventually discover the cause being other rows in the pieces_requests table that I hadn't thought about. The short answer to your second part is that I don't know why I did it that way. Presumably when I first wrote it there was a reason. [...] Content analysis details: (-51.6 points, 15.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -50 ALL_TRUSTED Passed through trusted hosts only via SMTP -2.6 BAYES_00 BODY: Bayesian spam probability is 0 to 1% [score: 0.0000] 1.0 RING_SAFE RING_SAFE X-Pg-Spam-Score: -2.3 (--) X-Archive-Number: 201209/23 X-Sequence-Number: 36825 Hi, Thanks for this. I did eventually discover the cause being other rows in the pieces_requests table that I hadn't thought about. The short answer to your second part is that I don't know why I did it that way. Presumably when I first wrote it there was a reason. Gary On Wednesday 12 September 2012 08:24:42 Samuel Gendler wrote: > I'll admit I don't see any reason why you should get duplicate rows based > on the data you've provided, but I am wondering why you are using the > subquery instead of just 'where r.r_id = 5695' > > select p.p_id, r.pr_ind > from pieces p > join pieces_requests r on p.p_id = r.p_id > where r.r_id = 5695 > > Though I'll be the first to admit that that seems to me like it ought to > return the exact same rows as both your queries. Are you sure you don't > have multiple rows in pieces_requests with the same p_id, r_id pairing? > Your join must be resulting in multiple rows for each p_id somehow. > -- Gary Stainburn Group I.T. Manager Ringways Garages http://www.ringways.co.uk