Re: Unexpected results with joins on dates

From: Alban Hertroys <dalroi(at)solfertje(dot)student(dot)utwente(dot)nl>
To: Tim Uckun <timuckun(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Unexpected results with joins on dates
Date: 2011-07-12 09:29:25
Message-ID: 1F0CD903-554C-4035-9931-C2382869F336@solfertje.student.utwente.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 12 Jul 2011, at 4:53, Tim Uckun wrote:

(Edited to take the irrelevant stuff out)

> select count(traffic.date) from traffic inner join sales on traffic.date = sales.date

> running this query gives me this result
> 25121853

> On the third select (two table join) it doesn't matter if I change it
> to a right join, full join left outer join I get the same number so it
> looks like it's doing a cross join no matter what. It also doesn't
> matter if I do a select count(*)
>
> Could somebody explain what is happening here?

Apparently you don't have any records in traffic where there's no corresponding date in sales or vice versa. Hence, outer joins give the same result as inner joins.

If that's not the case then we're going to need more details, such as the definitions of the tables.

Alban Hertroys

--
Screwing up is an excellent way to attach something to the ceiling.

!DSPAM:737,4e1c140112091081743685!

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alban Hertroys 2011-07-12 10:08:18 Re: [HACKERS] Creating temp tables inside read only transactions
Previous Message Alban Hertroys 2011-07-12 09:05:12 Re: ? about Composite Keys + ON DELETE/UPDATE SET NULL