Re: count() and multiple tables
От | Stephan Szabo |
---|---|
Тема | Re: count() and multiple tables |
Дата | |
Msg-id | Pine.BSF.4.21.0103191720420.27292-100000@megazone23.bigpanda.com обсуждение исходный текст |
Ответ на | Re: count() and multiple tables (Joseph Shraibman <jks@selectacast.net>) |
Ответы |
Re: count() and multiple tables
|
Список | 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]
В списке pgsql-sql по дате отправления: