GROUP BY or alternative means to group

Поиск
Список
Период
Сортировка
От Alexander Reichstadt
Тема GROUP BY or alternative means to group
Дата
Msg-id 3C1A86F1-347F-4E6E-A8E2-F34CE05F32F1@mac.com
обсуждение исходный текст
Ответы Re: GROUP BY or alternative means to group  (Bartosz Dmytrak <bdmytrak@eranet.pl>)
Solved [Re: GROUP BY or alternative means to group]  (Alexander Reichstadt <lxr@mac.com>)
Re: GROUP BY or alternative means to group  (Kiriakos Georgiou <kg.postgresql@olympiakos.com>)
Re: GROUP BY or alternative means to group  (Scott Marlowe <scott.marlowe@gmail.com>)
Список pgsql-general
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 FROM companies JOIN addresses_reference ON companies.id=addresses_reference.refid_companies LEFT JOIN addresses ON addresses_reference.refid_addresses=addresses.id GROUP 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 values for all companies that have more than one address, which is correct. But in some cases I only need one address and the 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 disregard any further addresses.

Is there any way to do this?

Thanks
Alex

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

Предыдущее
От: Carson Gross
Дата:
Сообщение: Upgrade questions
Следующее
От: Tim Uckun
Дата:
Сообщение: Re: full text search and ILIKE type clauses.