Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1guhRI-0005Ch-IW for pgsql-sql@arkaria.postgresql.org; Fri, 15 Feb 2019 17:38:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1guhRG-00056Z-Bw for pgsql-sql@arkaria.postgresql.org; Fri, 15 Feb 2019 17:38:14 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1guhRF-00056S-Vv for pgsql-sql@lists.postgresql.org; Fri, 15 Feb 2019 17:38:14 +0000 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1guhRD-0006N3-GK for pgsql-sql@lists.postgresql.org; Fri, 15 Feb 2019 17:38:12 +0000 Received: by mail-pf1-x435.google.com with SMTP id h1so5145248pfo.7 for ; Fri, 15 Feb 2019 09:38:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=SNluCssz8a/RZ0wGRmfeZnAMoHapV+aoHkeqN1F3u4I=; b=QRSFg6g4WK5oIMbwOJihn7VtrT2yYsD9CkqJVrNOqgjxnnFIiIgf7GGiWdW+c4IyUR /BpS7BodQS/MlMO0z0Glo7+l/QhQ+3wl6r3Hpfa+/376ExXygP4vvwNGOuJLSmUHAaCk srH6rLRUsT5+BKfj8V9sJKjx/UmZrvfSuAjCC2plyj5aglKE8f3IhIFEdtlGFuXLcj5s ZG6PoydAojGnfmCeiwbkog9k4es00lzfuPBz+nZOW+4WqaEGZD7qTQ2vT08TUy+OaKHr aoTL/eX4TUTwLMu1rbN6XNGG0c516orLyrOqW5EyNL+gsBfQyXN4Np6ilnDUN3Pjf+Cg remA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=SNluCssz8a/RZ0wGRmfeZnAMoHapV+aoHkeqN1F3u4I=; b=HTsE/HiNi+GJRlDIYP6MnlXyINJYSlAiUIdv69Rsb98xySQl54y9DBywB/5PTNBqor IMF/VTeKcJXJdUHstM29mxUmFS9VkAC+rJTC0Cy0+66VICKcL6Psjy/8RFJ2rc5UHebq 9FmTgMX2KTfVGk+NW23O5yo3p1sBpIdbg8Z6RbyVKKJJAYWEo5O28vEOsIi6I1h87pXO qe2NZKLJ5MeapLhroyHaTSaalJEfKtB014zo5GVhOMCcPHhY9mvGfKxTcskwvR3bfT/b U4mmk9pw0TIK2vrREq8vTTl1w5NLkw/n4BO7ITvDJ+3KYihw3HEQHgG4pBRgZw5Fmqqu m11A== X-Gm-Message-State: AHQUAuZ6oG70vmX0CvzqXStA1CqmAKIh6CoKBCEd729xqwfIh5XSGoc1 iajafc4v/ZKCV6+7VArTu3gnptpN X-Google-Smtp-Source: AHgI3IZCejD0y+/GBaty7eoJUtXYdXTi8CFlFtkqYnBuCMaWzV7xG1vc5Soy078c0HZTZnCg+LabzQ== X-Received: by 2002:a63:480c:: with SMTP id v12mr6611386pga.115.1550252290314; Fri, 15 Feb 2019 09:38:10 -0800 (PST) Received: from h004708.hci.utah.edu ([155.100.47.3]) by smtp.gmail.com with ESMTPSA id j197sm19317847pgc.76.2019.02.15.09.38.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Feb 2019 09:38:09 -0800 (PST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 12.2 \(3445.102.3\)) Subject: Re: Help on SQL query From: Rob Sargent In-Reply-To: <87k1i1klp2.fsf@news-spur.riddles.org.uk> Date: Fri, 15 Feb 2019 10:38:08 -0700 Cc: Ian Tan , pgsql-sql@lists.postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: <499C11DB-F3CF-4316-845A-19ABCAF52962@gmail.com> References: <87k1i1klp2.fsf@news-spur.riddles.org.uk> To: Andrew Gierth X-Mailer: Apple Mail (2.3445.102.3) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk > On Feb 15, 2019, at 10:28 AM, Andrew Gierth = wrote: >=20 >>>>>> "Ian" =3D=3D Ian Tan writes: >=20 > 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: >=20 > 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: >=20 > 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=3Dbom.parent_id) > join car_parts cpart on (cpart.id=3Dbom.child_id); >=20 > --=20 > Andrew (irc:RhodiumToad) >=20 Andrew, will you do my homework too?=