Re: [NOVICE] How to get n records from parent table and theirchildren - Mailing list pgsql-novice

From Laurenz Albe
Subject Re: [NOVICE] How to get n records from parent table and theirchildren
Date
Msg-id 1510816869.2639.14.camel@cybertec.at
Whole thread Raw
In response to [NOVICE] How to get n records from parent table and their children  (JORGE MALDONADO <jorgemal1960@gmail.com>)
List 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 by date:

Previous
From: john snow
Date:
Subject: [NOVICE] group by rollup and cube
Next
From: Laurenz Albe
Date:
Subject: Re: [NOVICE] group by rollup and cube