Re: How do I alter an existing column and add a foreign key which is a Primary key to a table?

From: Avin Kavish <avinkavish(at)gmail(dot)com>
To: Karen Goh <karenworld(at)yahoo(dot)com>
Cc: Ron <ronljohnsonjr(at)gmail(dot)com>, pgsql-admin(at)lists(dot)postgresql(dot)org
Subject: Re: How do I alter an existing column and add a foreign key which is a Primary key to a table?
Date: 2019-07-21 16:10:59
Message-ID: CAFpscOTUNm2JZ1Vbv2h+BCnW5k7+ZJXWSBv_aP69Z7gRZo2Qhw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin pgsql-sql

Hey Karen,

That query is pretty much an inner join with a filter that selects a single
value from the matching rows.
It's picking the tutor's zipcode from the tutor table where any tutor is
teaching a subject called "Angela Merkel".
For this to happen, it needs to join the tutor subjects with the tutor
details table using the tutor id as the common factor.

Perhaps you should try www.stackoverflow.com for SQL guidance. They might
be able to explain in detail what you are doing (wrong).
Make sure to provide a complete example
<https://stackoverflow.com/help/minimal-reproducible-example> showing all
the involved relations and references and any queries your wrote. This is
really
important or they downvote/close questions. (your original email is not
sufficient detail)

Regards,
Avin

On Sun, Jul 21, 2019 at 8:54 PM Karen Goh <karenworld(at)yahoo(dot)com> wrote:

>
>
>
>
>
> On Sunday, July 21, 2019, 11:13:58 PM GMT+8, Ron <ronljohnsonjr(at)gmail(dot)com>
> wrote:
>
>
> On 7/21/19 10:10 AM, Karen Goh wrote:
>
> >
> > On Sunday, July 21, 2019, 11:06:16 PM GMT+8, David G. Johnston
> > <david(dot)g(dot)johnston(at)gmail(dot)com> wrote:
> >
> >
> > On Sunday, July 21, 2019, Karen Goh <karenworld(at)yahoo(dot)com> wrote:
> >
> >
> > Is there a way for me to generate an entity table diagram vis pgAdmin4 or
> > PSQL ?
> >
> >
> > Just write the 5 or so tables out in a somewhat compressed format. Psql
> > doesn’t and I don’t know about pgadmin
> >
> > Here is a compressed format :
> >
> > s_tutor
> > --------
> > zipcode(text)
> > tutor_id (I just checked this is becomes a 'serial id ?' based on the
> > generated sql
> >
> > ALTER TABLE public.s_tutor ALTER COLUMN tutor_id ADD GENERATED BY DEFAULT
> > AS IDENTITY (
> > SEQUENCE NAME public.tutor_strtutorid_seq
> > START WITH 1
> > INCREMENT BY 1
> > NO MINVALUE
> > NO MAXVALUE
> > CACHE 1
> > );
> >
> > tutor_subject
> > ----------------
> > tutor_id
> > subject_Names
>
>
> select s_tutor.zipcode
> from s_tutor, tutor_subject
> where s_tutor.tutor_id = tutor_subject.tutor_id
> and tutor_subject.subject_names ='Angela Merkel'
>
> Hi Ron,
>
> Could you explain why you select s_tutor.zipcode from tutor_subject since
> there is no zipcode inside tutor_subject?
>
> Perhaps my reasoning is wrong and I really want to have your expert view.
>
>
> --
> Angular momentum makes the world go 'round.
>
>
>
>

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Karen Goh 2019-07-21 16:26:43 Re: How do I alter an existing column and add a foreign key which is a Primary key to a table?
Previous Message Karen Goh 2019-07-21 15:44:19 Fw: How do I alter an existing column and add a foreign key which is a Primary key to a table?

Browse pgsql-sql by date

  From Date Subject
Next Message Karen Goh 2019-07-21 16:26:43 Re: How do I alter an existing column and add a foreign key which is a Primary key to a table?
Previous Message Karen Goh 2019-07-21 15:44:19 Fw: How do I alter an existing column and add a foreign key which is a Primary key to a table?