Unexpected results when joining on date fields - Mailing list pgsql-general

From Tim Uckun
Subject Unexpected results when joining on date fields
Date
Msg-id CAGuHJrMYkWt15=Tf7e-dKhqkeEAnzpcPpdTwF9LycF2ycJyJJA@mail.gmail.com
Whole thread Raw
Responses Re: Unexpected results when joining on date fields  (Rick Genter <rick.genter@gmail.com>)
Re: Unexpected results when joining on date fields  (Alban Hertroys <dalroi@solfertje.student.utwente.nl>)
List pgsql-general
I have two tables, traffic and sales. Each one has a date field and
lists the traffic and sales broken down by various parameters
(multiple rows for each date).

If I run  select (select count(*) from traffic) as traffic, (select
count(*) from sales) as sales; I get the following  49383;167807

if I run   select count(*) from traffic t inner join sales s on t.date
= s.date  I get 24836841.

If I change the join to a left join, right join, full join I get the
same number of records.

So I created a data table which just has the dates in it and ran this query.

select count(d.date) from dates d
inner join traffic t on t.date = d.date
inner join sales s on s.date = d.date

And I get the same number 24836841

Same goes for right joins on the above query. Left joins of course
give a different answer as there are more dates in the date table than
there are in the other tables.

I am a bit perplexed by what is happening here.

Cheers

pgsql-general by date:

Previous
From: 赵伟宇
Date:
Subject: Fw: Re: [BUGS] BUG #6099: Does pgcluster support hibernate?
Next
From: Rick Genter
Date:
Subject: Re: Unexpected results when joining on date fields