I'm what I might call a "novice hack" at SQL in general, so forgive any
blatant oversighs on my part.
My problem is this, I have three tables as such:
The contact_join table works by holding the name of the table the contact is
for in the parent_table field, and the id of the record in that table.
A simple example of the three tables might be:
23, 'South / Florida', '234'
11, 'John', 'Doe', 'generic(at)aol(dot)com'
11, 23, 'region', 'Manager'
There are numerous tables that a record in the contact table might be
connected to which is why I have the parent_table field. If there is a
better way to do this, I'm all ears, but I'd rather my question were answerd
since I dont want to rewrite the code I have already....which leads me to
I want a view that will show all the relevant information about a region,
namely the regino_name, region_no, c.name_first, c.name_last, c.email and
cj.relationship (contact c, contact_join cj). I have come up with this query
(I'm new at joins if you couldnt guess):
((cj.parent_id = r.region_id)))
((c.id = cj.contact_id)))
(cj.parent_table = 'region');
The problem is, sometimes no contact information has been entered yet, and I
need to be able to see regions even if they have no contact information.
The above query will only show items that have a contact_join entry with the
parent_table as 'region'.
In pseudocode, I want this:
SELECT /* region data from region table, and if contact information exists
for a region, select the contact information as well, otherwise leave the
contact fields blank */
Follow? Let me know if this dosent make any sense.
Any help would be appriciated.
Tom von Schwerdtner
Webmaster, Facilities Plus Inc.
pgsql-novice by date
|Next:||From: Mark Thomas||Date: 2002-06-07 18:27:44|
|Previous:||From: Wim||Date: 2002-06-07 14:20:18|
|Subject: HELP! Cannot access table!!!!|