Re: GROUP BY or alternative means to group

Поиск
Список
Период
Сортировка
От Michael Gould
Тема Re: GROUP BY or alternative means to group
Дата
Msg-id r02pdd0qpqha0ar3wq6kqxj1.1331583485074@email.android.com
обсуждение исходный текст
Ответ на GROUP BY or alternative means to group  (Alexander Reichstadt <lxr@mac.com>)
Ответы Re: GROUP BY or alternative means to group
Список pgsql-general
You need to include all columns that are not aggregrative columns in the group by.  Even though that is the standard it
isa pain to list all columns even if you don't need them 

Best Regards

Michael Gould

Sent from Samsung mobile

Alexander Reichstadt <lxr@mac.com> wrote:

>Hi,
>
>the following statement worked on mysql but gives me an error on postgres:
>
>column "addresses.address1" must appear in the GROUP BY clause or be used in an aggregate function
>
>I guess I am doing something wrong. I read the web answers, but none of them seem to meet my needs:
>
>SELECT
companies.id,companies.name,companies.organizationkind,addresses.address1,addresses.address2,addresses.city,addresses.zip
FROMcompanies JOIN addresses_reference ON companies.id=addresses_reference.refid_companies LEFT JOIN addresses ON
addresses_reference.refid_addresses=addresses.idGROUP BY companies.id; 
>
>
>What I did now was create a view based on above statement but without grouping. This returns a list with non-distinct
valuesfor all companies that have more than one address, which is correct. But in some cases I only need one address
andthe problem is that I cannot use distinct. 
>
>I wanted to have some way to display a companies list that only gives me the first stored addresses related, and
disregardany further addresses. 
>
>Is there any way to do this?
>
>Thanks
>Alex

В списке pgsql-general по дате отправления:

Предыдущее
От: Michael Gould
Дата:
Сообщение: Re: version controlling postgresql code
Следующее
От: Michael Gould
Дата:
Сообщение: Re: what Linux to run