Re: deciding on one of multiple results returned

Поиск
Список
Период
Сортировка
От Seth Gordon
Тема Re: deciding on one of multiple results returned
Дата
Msg-id CACJOC70EsC47kqCOb1CQrASc93voCKuiB1pdweTz18YxVGZA-g@mail.gmail.com
обсуждение исходный текст
Ответ на deciding on one of multiple results returned  (Wes James <comptekki@gmail.com>)
Ответы Re: deciding on one of multiple results returned  (Wes James <comptekki@gmail.com>)
Список pgsql-sql
If you only want one value per id, then your query should be “SELECT DISTINCT ON (id) ...”

If you care about which particular value is returned for each ID, then you have to sort the results: e.g., if you want the minimum value per id, your query should be “SELECT DISTINCT ON (id) ... ORDER BY value”. The database will sort the query results before running them through the DISTINCT filter.

On Fri, Dec 21, 2012 at 11:31 AM, Wes James <comptekki@gmail.com> wrote:
If a query returns, say the following results:

id   value
0      a
0      b
0      c
1      a
1      b



How do I just choose a preferred element say value 'a' over any other elements returned, that is the value returned is from a subquery to a larger query?

Thanks.

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

Предыдущее
От: "David Johnston"
Дата:
Сообщение: Re: deciding on one of multiple results returned
Следующее
От: Wes James
Дата:
Сообщение: Re: deciding on one of multiple results returned