Re: weird join producing too many rows

From: Gary Stainburn <gary(dot)stainburn(at)ringways(dot)co(dot)uk>
To: Samuel Gendler <sgendler(at)ideasculptor(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: weird join producing too many rows
Date: 2012-09-12 08:17:00
Message-ID: 201209120917.00531.gary.stainburn@ringways.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Rodrigo Rosenfeld Rosas 2012-09-12 21:44:15 ORDER BY COLUMN_A, (COLUMN_B or COLUMN_C), COLUMN_D
Previous Message Samuel Gendler 2012-09-12 07:24:42 Re: weird join producing too many rows