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 1hpClZ-0001A9-3H for pgsql-admin@arkaria.postgresql.org; Sun, 21 Jul 2019 14:24:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hpClX-0000Wx-Kx for pgsql-admin@arkaria.postgresql.org; Sun, 21 Jul 2019 14:24:43 +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 1hpClX-0000Wq-8j for pgsql-admin@lists.postgresql.org; Sun, 21 Jul 2019 14:24:43 +0000 Received: from sonic308-1.consmr.mail.bf2.yahoo.com ([74.6.130.40]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1hpClU-0003UG-0F for pgsql-admin@lists.postgresql.org; Sun, 21 Jul 2019 14:24:42 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1563719078; bh=mrzmTnlMVc4uhUP0BKeIe5YC/yDjUKZlNt5prJBgj18=; h=Date:From:To:In-Reply-To:References:Subject:From:Subject; b=DMM8HVbk42beRK8fATt63HI6bf/0RPyB+h8vqXemtILEy23n8TXyTT/sUhx7KMbWBlImWZRPxQfwAvGy6UVGqkN4BeEZm3AeKToflU+QdLopC0ja5c0hrd6VBvqvzv3vTU7D7BUdUoqE2LSWBxfSyyEiOQN9aAUeoo57fI2CUNJ2+4swEaaUcmxCU86QyYG6y6/rNBVRNlZKq1MLrpwGEcv4lLVZX73noLmhUmIt5EvMSQWvcGuq7tKpVGk21Y1b19mRZVADI+iSgcQedK9k1jAttGReIZOFkhSKmxXzv9e/htizh3S/HPiXxkGGu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cIQDG_zfEXAXwnWp9qA8I8Gs.G3jbC9Yb tMdon.nOQ4g2pGLTdZTCb678WiABjwP8qPEpr8MqcDXfV6CEnG2GKNDxosnezsbIdYUc2Y0fJ91P 1vvm5b2zmvEXXhgj.JDK8xs9Ou98DnSRqLcIVs2XZZRpusM4C77XALRba60V2I05Th3ydtq1x1JJ PfKNYgbeuBR5_Wzy_h8XkEQN3nB1vn_hbXXkRIm506jCPBQfIjlCFzS.ypQUzWswOE8yEHLVVLMF claXIYj.0KCiVA1HOh5kqaC69e6NzFcqcQA-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic308.consmr.mail.bf2.yahoo.com with HTTP; Sun, 21 Jul 2019 14:24:38 +0000 Date: Sun, 21 Jul 2019 14:24:35 +0000 (UTC) From: Karen Goh To: pgsql-admin@lists.postgresql.org, Ron Message-ID: <1745586001.2633224.1563719075867@mail.yahoo.com> In-Reply-To: <923fb3b1-90e9-e0b5-bc5b-d896128c3f28@gmail.com> References: <820008379.2579287.1563670685484@mail.yahoo.com> <5CE41E80-274A-44DA-9553-E2DCA260F751@jakobs.com> <385857992.2643116.1563717238725@mail.yahoo.com> <923fb3b1-90e9-e0b5-bc5b-d896128c3f28@gmail.com> Subject: Re: How do I alter an existing column and add a foreign key which is a Primary key to a table? MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_2633223_1912391500.1563719075866" Content-Length: 3608 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ------=_Part_2633223_1912391500.1563719075866 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On Sunday, July 21, 2019, 10:12:33 PM GMT+8, Ron wrote: On 7/21/19 8:53 AM, Karen Goh wrote: > > On Sunday, July 21, 2019, 3:28:10 PM GMT+8, Holger Jakobs > wrote: > > Am 21. Juli 2019 02:58:05 MESZ schrieb Karen Goh : > [snip] > > This looks like a 1:1 relationship which is to be avoided. > > One ALTER TABLE command either adds a primary or a foreign key. There is > no FK without the keyword REFERENCES. > > FK relationships help in keeping the data consistent, but they are totally > unrelated to/useless for SELECT statements and their JOIN operations. This > is a common misconception. > > Hi Holger, > > After reading your reply, I am confused now. > > Cos without creating foreign key in my tutor_subject how am I going to > retrieve the zipcode at s_tutor table that meet the list of subject_name > and tutor_id in tutor_subject ? There should have some reference right ? > If not, how does the database tell this zipcode belong to which tutor_id ? The reference is in the SELECT statement, not in the FK definition. SELECT s_tutor.zip_code from subject_tutor, s_tutor where s_tutor.tutor_id = subject_tutor.tutor_id and subject_tutor.subject_name = 'Angela Merkel'; Hi Ron, You can't Select s_tutor.zip_code from subject_tutor as zip_code belongs to s_tutor table. Hence, I wrote my last message about my confusion. -- Angular momentum makes the world go 'round. ------=_Part_2633223_1912391500.1563719075866 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable





On Sunday, July 21, 2019, 10:12:33= PM GMT+8, Ron <ronljohnsonjr@gmail.com> wrote:


On 7/21/19= 8:53 AM, Karen Goh wrote:
>
> On Sunday, July 21, 2019, 3:28:1= 0 PM GMT+8, Holger Jakobs
> <holger@jakobs.com> wrote:
><= br>> Am 21. Juli 2019 02:58:05 MESZ schrieb Karen Goh <karenworld@yah= oo.com>:
>
[snip]

>
> This looks like a 1:1 rel= ationship which is to be avoided.
>
> One ALTER TABLE command e= ither adds a primary or a foreign key. There is
> no FK without the k= eyword REFERENCES.
>
> FK relationships help in keeping the dat= a consistent, but they are totally
> unrelated to/useless for SELECT = statements and their JOIN operations. This
> is a common misconceptio= n.
>
> Hi Holger,
>
> After reading your reply, I a= m confused now.
>
> Cos without creating foreign key in my tuto= r_subject how am I going to
> retrieve the zipcode at s_tutor table t= hat meet the list of subject_name
> and tutor_id in tutor_subject ? T= here should have some reference right ?
> If not, how does the databa= se tell this zipcode belong to which tutor_id ?


The reference is= in the SELECT statement, not in the FK definition.

SELECT s_tutor.z= ip_code
from subject_tutor, s_tutor
where s_tutor.tutor_id =3D subjec= t_tutor.tutor_id
and subject_tutor.subject_name =3D 'Angela Merkel&#= 39;;

Hi Ron,

You can't Select s_tutor.zip_code from subje= ct_tutor as zip_code belongs to s_tutor table.

Hence, I wrote my las= t message about my confusion.



--
Angular momentum makes = the world go 'round.



=20 ------=_Part_2633223_1912391500.1563719075866--