| From: | Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com> |
|---|---|
| To: | Joseph Shraibman <jks(at)selectacast(dot)net> |
| Cc: | "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org> |
| Subject: | Re: count() and multiple tables |
| Date: | 2001-03-20 01:23:24 |
| Message-ID: | Pine.BSF.4.21.0103191720420.27292-100000@megazone23.bigpanda.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-sql |
> > And postgres tries to be helpful again... :( [I *really* dislike this
> > adding to from list thing] Technically the above should be illegal
> > because no from list contains u or a. Postgres is adding them to the
> > from list for you.
> >
> I get the same result if I do:
> select count(d.id) from d where status = 2 and d.id = u.dkey and
> u.status = 2 and not u.b and u.akey = a.key and a.status = 3;
>
> So in standard SQL all the tables you join accross are required to be in
> the FROM?
Basically, yes. It's more complicated than that probably (what isn't in
SQL), but that's the general idea.
Postgres assumes your query is
select count(*) from d,u,a ...
Because d.id was guaranteed to be unique, you might be able to
count(distinct d.id) and get the result you want. [I think the
subquery is a nicer way of representing it]
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Joseph Shraibman | 2001-03-20 02:05:26 | Re: VACUUM kills Index Scans ?! |
| Previous Message | Tim Pizey | 2001-03-20 00:40:46 | Re: Invalid (null) int8, can't convert to float8 |