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 1guilQ-0003UF-GH for pgsql-sql@arkaria.postgresql.org; Fri, 15 Feb 2019 19:03:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1guilP-0007du-9y for pgsql-sql@arkaria.postgresql.org; Fri, 15 Feb 2019 19:03:07 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1guilP-0007dn-3B for pgsql-sql@lists.postgresql.org; Fri, 15 Feb 2019 19:03:07 +0000 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1guilN-0002zt-3p for pgsql-sql@lists.postgresql.org; Fri, 15 Feb 2019 19:03:06 +0000 Received: by mail-pf1-x42a.google.com with SMTP id s22so5263063pfh.4 for ; Fri, 15 Feb 2019 11:03:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=yLJw9/cF1jERB0tNrtoqH6kpRuTGR3+e4KbzEMwc/ws=; b=Sb9GvUS2r+reQiAZUzbgmVumPwJHChGDqvJACdg3KUJzJZu5P7RxhOy8vdopQRIxdo +USpwQj+mvezYjYpiabfvVKxEiDsFyBJ8gHZkBfn7NXYFpZh/2y0Nk7hy5kCokeRlRXH Dt8F8eJDFCl/dNTy4LJk6NOD5pmGR4JQ6q4YM/Bwt/nUd9dTWnrm0SddRHhzwjfUykqu PnbP/dCPbEtX/fsDibOx2+CP2mkBSxKBwz53pUoTfhbMra5Lj559D7kXaPNSzIq32HjK g4kq5df31aQZdchSutWjKN4QZFAxYb1Ot4kGpg5w0VZimK3Fm2nFfiKLPgrIkiFhpyGx Zzng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=yLJw9/cF1jERB0tNrtoqH6kpRuTGR3+e4KbzEMwc/ws=; b=Ji7te7WuTQlDwzK+RfE6Ku0a12lORmLwJ1YEg/dVmMYIX0FBztrH8vW8GgTctM5Sce HrZM9eAsnGWQJtw+By3PLF9UsF8Oa/dOT+XqT7o70TtTqp6Bfs4O5slgu9f8WePDDyTH hsIOO+YzJL9FyPX9auZYyMLrQ1aFMPrt/neDYil+phgZ5MVECl1s4ogpGcFzozZ3cZOJ UxkALy709MSwRVTuNHbeeV6n3/bGEgeUcHTnoOB70HIMlo39V3xIVDMbTdymgqMd26tP geScRzgGOXANv7Dnx/5la2TcAR9tpEQslgDy81qyW5RnStkokHTmCp0AQlObTlaxPFU+ YZyw== X-Gm-Message-State: AHQUAuZYmz0vdkoCbbO/mb/J1pt6DVOCGY6kWZ0tghemua5sq/efUZdT cAGZuKurmmXNkA8mlvGWLAnzUfjo X-Google-Smtp-Source: AHgI3IbmP0NCILWYUoE2OWIeBVkZ8Gw4XgKFvwN6xF4hXxykIsKs2oW8pCU72Dx9L5LiPLCmxbwZ3Q== X-Received: by 2002:a63:1e12:: with SMTP id e18mr6750557pge.76.1550257382467; Fri, 15 Feb 2019 11:03:02 -0800 (PST) Received: from [10.104.134.14] ([155.100.47.6]) by smtp.gmail.com with ESMTPSA id i71sm20146770pfi.170.2019.02.15.11.03.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Feb 2019 11:03:01 -0800 (PST) Subject: Re: Help on SQL query To: Ian Tan Cc: Andrew Gierth , pgsql-sql@lists.postgresql.org References: <87k1i1klp2.fsf@news-spur.riddles.org.uk> <499C11DB-F3CF-4316-845A-19ABCAF52962@gmail.com> From: Rob Sargent Message-ID: <951259bf-280d-ce6d-7493-cdbb628074f0@gmail.com> Date: Fri, 15 Feb 2019 12:03:00 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2/15/19 11:16 AM, Ian Tan wrote: > Hello Andrew, > Thank you, I appreciate your response and your help. > > Hello Rob, > I learn in my own time and had no one to ask. If pgsql-sql is not the > correct forum for these kinds of question, kindly let me know. > > Thank you. > > Regards, > Ian > > On Fri, 15 Feb 2019 at 17:38, Rob Sargent wrote: >> >> >>> On Feb 15, 2019, at 10:28 AM, Andrew Gierth wrote: >>> >>>>>>>> "Ian" == Ian Tan 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? My apologies.  It looked suspiciously like a homework question to me.