Re: join with 1 row limit

Поиск
Список
Период
Сортировка
От Jasen Betts
Тема Re: join with 1 row limit
Дата
Msg-id iguk43$m38$1@reversiblemaps.ath.cx
обсуждение исходный текст
Ответ на Re: join with 1 row limit  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-novice
On 2011-01-15, Behringer Behringer <behringerdj@yahoo.com> wrote:
> Sorry for that
>
>> > SELECT *
>> > FROM
>> > products p LEFT JOIN
>> > products_images pi ON p.id = pi.product_id  LIMIT
>> 1
>> > WHERE products.company = 7
>
> I just want to get one row from images table for each product row from products table.

SELECT distinct on (p.id)
  *
FROM products p
  LEFT JOIN products_images pi
    ON p.id = pi.product_id WHERE products.company = 7

or perhaps:

SELECT *
FROM products p LEFT JOIN
  ( SELECT * FRPM products_images pi where p.id = pi.product_id limit
1) as foo ON TRUE
WHERE products.company = 7

an


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

Предыдущее
От: Behringer Behringer
Дата:
Сообщение: Re: join with 1 row limit
Следующее
От: Josh Kupershmidt
Дата:
Сообщение: Re: async fast-path calls?