agora inbox for pgsql-sql@postgresql.org  
help / color / mirror / Atom feed
From: Rob Sargent <robjsargent@gmail.com>
To: Andrew Gierth <andrew@tao11.riddles.org.uk>
Cc: Ian Tan <iantan1268@gmail.com>
Cc: pgsql-sql@lists.postgresql.org
Subject: Re: Help on SQL query
Date: Fri, 15 Feb 2019 10:38:08 -0700
Message-ID: <499C11DB-F3CF-4316-845A-19ABCAF52962@gmail.com> (raw)
In-Reply-To: <87k1i1klp2.fsf@news-spur.riddles.org.uk>
References: <CAAj7RQ-vF3kPaC7Y5csgjL75Bo=FotP6W=s2LsRhirVE78b4HQ@mail.gmail.com>
	<87k1i1klp2.fsf@news-spur.riddles.org.uk>



> On Feb 15, 2019, at 10:28 AM, Andrew Gierth <andrew@tao11.riddles.org.uk> wrote:
> 
>>>>>> "Ian" == Ian Tan <iantan1268@gmail.com> writes:
> 
> Ian> How do I write an SQL query so that the "name" text in car_parts
> Ian> are added to the bill_of_materials table, so that it looks like
> Ian> this:
> 
> The only trick with this is that you need to join the car_parts table
> twice (once for parent and once for child), and to do that you need to
> give it different alias names:
> 
> select bom.parent_id,
>       ppart.name as parent_name,
>       bom.child_id,
>       cpart.name as child_name
>  from bill_of_materials bom
>  join car_parts ppart on (ppart.id=bom.parent_id)
>  join car_parts cpart on (cpart.id=bom.child_id);
> 
> -- 
> Andrew (irc:RhodiumToad)
> 

Andrew, will you do my homework too?



view thread (7+ messages)  latest in thread

Message-ID: <499C11DB-F3CF-4316-845A-19ABCAF52962@gmail.com>
Permalink:  ../499C11DB-F3CF-4316-845A-19ABCAF52962@gmail.com/
Also on:    postgresql.org/message-id/499C11DB-F3CF-4316-845A-19ABCAF52962@gmail.com

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: robjsargent@gmail.com, andrew@tao11.riddles.org.uk, iantan1268@gmail.com, pgsql-sql@lists.postgresql.org
  Subject: Re: Help on SQL query
  In-Reply-To: <499C11DB-F3CF-4316-845A-19ABCAF52962@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox