Re: JOINING TWO TABLES

From: "Ashish Karalkar" <ashish(dot)karalkar(at)info-spectrum(dot)com>
To: <vamseelist(at)gmail(dot)com>
Cc: <pgsql-novice(at)postgresql(dot)org>, "Richard Broersma Jr" <rabroersma(at)yahoo(dot)com>
Subject: Re: JOINING TWO TABLES
Date: 2007-08-07 08:07:50
Message-ID: 016901c7d8ca$10c68eb0$170211ac@LIONKING.COM
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Even you can drop the manager table and only keep employees table containg
mangers and employees to and then self join the table.
and then query

select e.employee_name , e1.employee_name as manager_name from
employee e, employee e1
where e.manager_id=e1.employee_id

With Regards
Ashish

----- Original Message -----
From: "Richard Broersma Jr" <rabroersma(at)yahoo(dot)com>
To: <vamseelist(at)gmail(dot)com>; <pgsql-novice(at)postgresql(dot)org>
Sent: Monday, August 06, 2007 9:57 PM
Subject: Re: [NOVICE] JOINING TWO TABLES

>
> --- 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.
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Have you searched our list archives?
>
> http://archives.postgresql.org

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Angelica Garcia 2007-08-07 13:25:09 Arrow keys do not work while using psql
Previous Message Luca Ferrari 2007-08-07 07:52:40 buffer page lock vs tuple lock (?)