Skip site navigation (1) Skip section navigation (2)

Re: JOINING TWO TABLES

From: Richard Broersma Jr <rabroersma(at)yahoo(dot)com>
To: vamseelist(at)gmail(dot)com, pgsql-novice(at)postgresql(dot)org
Subject: Re: JOINING TWO TABLES
Date: 2007-08-06 16:27:35
Message-ID: 328187.8244.qm@web31813.mail.mud.yahoo.com (view raw or flat)
Thread:
Lists: pgsql-novice
--- vamseelist(at)gmail(dot)com wrote:
> I mean d,e got 1 and 2 in mgr table.
> d,e got 4,5 in new table.
> 
> I would like to replace 1 1 2 with 4 4 5.
> 
> I would like to modify above table as

I would modify your manager and employees tables to look like:


CREATE TABLE Employees (
  emp_id SERIAL PRIMARY KEY,
  name text,
  mgr_id INTEGER);

CREATE TABLE Managers (
  mgr_id INTEGER PRIMARY KEY REFERENCES Employees( emp_id ));

   ALTER TABLE Employees 
ADD CONSTRAINT managers_of_employees
   FOREIGN KEY ( mgr_id )
    REFERENCES Managers( mgr_id );

Regards,
Richard Broersma Jr.

In response to

Responses

pgsql-novice by date

Next:From: Angelica GarciaDate: 2007-08-06 19:55:02
Subject: tree-like structures in pgsql
Previous:From: vamseelistDate: 2007-08-06 16:07:54
Subject: JOINING TWO TABLES

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group