Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

One person, three trees, three labels

Status
Not open for further replies.

zorglub76

Programmer
Feb 20, 2007
2
0
0
YU
Hi all,
Sorry that I couldn't put my subject any better than this.. :)
Here's the description of the problem I have:

I have tables "USER", "TREE" and "LABEL". Each user has a primary, secondary and location tree, each of which is stored in "TREE" table. Each tree has its name in "LABEL" table.
I need to create a query that would return:

"USER".id, "USER".loctree_id, loctree's label, "USER".primtree_id, primtree's label, "USER".sectree_id, sectree's label

So, basically, I need three labels in a single query.
How do I do that?

Thanks in advance.
 
Code:
SELECT "USER".id
     , "USER".loctree_id
     , loctreelabel.name AS loctree_name
     , "USER".primtree_id
     , primtreelabel.name AS primtree_name
     , "USER".sectree_id
     , sectreelabel.name AS sectree_name
  FROM "USER"
INNER
  JOIN TREE AS loctree
    ON loctree.id = "USER".loctree_id
INNER
  JOIN LABEL AS loctreelabel
    ON loctreelable.id = loctree.lable_id
INNER
  JOIN TREE AS primtree
    ON primtree.id = "USER".primtree_id
INNER
  JOIN LABEL AS primtreelabel
    ON primtreelable.id = primtree.lable_id
INNER
  JOIN TREE AS sectree
    ON sectree.id = "USER".sectree_id
INNER
  JOIN LABEL AS sectreelabel
    ON sectreelable.id = sectree.lable_id

r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top