Re: [NOVICE] How to get n records from parent table and theirchildren

Поиск
Список
Период
Сортировка
От Laurenz Albe
Тема Re: [NOVICE] How to get n records from parent table and theirchildren
Дата
Msg-id 1510816869.2639.14.camel@cybertec.at
обсуждение исходный текст
Ответ на [NOVICE] How to get n records from parent table and their children  (JORGE MALDONADO <jorgemal1960@gmail.com>)
Список pgsql-novice
JORGE MALDONADO wrote:
> I have a parent and child tables and need to get "n" records from parent table
> and all of the records in child for such "n" records in parent. What can be a good approach?

I'd try it as follows:

SELECT ...
FROM (SELECT p_id, ...     FROM parent     LIMIT 42) p  JOIN child c     USING (p_id);

This assumes that "p_id" is the key column in "parent"
and the foreign key column in "child".

Yours,
Laurenz Albe


-- 
Sent via pgsql-novice mailing list (pgsql-novice@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice

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

Предыдущее
От: john snow
Дата:
Сообщение: [NOVICE] group by rollup and cube
Следующее
От: Laurenz Albe
Дата:
Сообщение: Re: [NOVICE] group by rollup and cube