Re: normalization - two linked fields in one table

From: Theo Peterbroers <peterbroers_at_floron.leidenuniv.nl>
Date: 11 Nov 2002 05:00:06 -0800
Message-ID: <39bb2c10.0211110500.2b73b7ff_at_posting.google.com>


"Trooper" <andrew_zx5_at_NOSPAMyahoo.com> wrote in message news:<JhIz9.796567$Ag2.27051080_at_news2.calgary.shaw.ca>...
> I'm setting up a small web based program to help manage "Tasks" between
> family members. Kind of like Bugzilla, but on a way smaller scale.
> My problem is that a "Task" has two fields in it that relate to the same
> table:
>
> Task User
> ==== ====
> TaskID UserID
> assigned_to name
> poster_id
>
> assigned_to and poster_id are linked to the UserID.
<...>
> can't figure out how
> to pull a name from the User table for each of the two fields in the Task
> table.
>
You need to join the user table twice, once for assignee, then for poster:

SELECT t.TaskID, a.name as Assignee, p.name as Poster FROM (Task as t INNER JOIN User as a ON t.assigned_to=a.UserID)

                INNER JOIN User as p ON t.poster_id=a.UserID
Received on Mon Nov 11 2002 - 14:00:06 CET

Original text of this message