How do I make sure that an employee and supervisor belong to the same company?

From: Matthew Wilson <matt(at)tplus1(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: How do I make sure that an employee and supervisor belong to the same company?
Date: 2008-04-14 17:36:13
Message-ID: slrng075gd.9oi.matt@sprout.tplus1.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I have an employees table and one column in the employees table is
"supervisor_id" which is an FK to the id column.

I have employees from numerous companies all in the same table. I have
a column called company_id that indicates the company.

I want to make sure that an employee chooses a supervisor from the same
company. I have a column called company_ID. How do I make sure that
the employee company ID matches the supervisor's company ID?

Do I need to use a trigger or is there a way I can do this with foreign
keys?

TIA

Matt

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2008-04-14 17:36:37 Re: The default text search configuration will be set to "simple" ?
Previous Message Chris Browne 2008-04-14 17:34:36 Re: Unacceptable postgres performance vs. Microsoft sqlserver