Wrox Home  
Search P2P Archive for: Go

  Return to Index  

sql_language thread: Looping and variables


Message #1 by "sean hayes" <sean@b...> on Mon, 26 Nov 2001 23:03:45
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01C176CF.1850BF9C
Content-Type: text/plain

Welcome to the world of inheritance. The grandchild table inherits the
category for the grandparent table from its parent table. Example of how to
implement this:

Table1 -- Grandparent
Table1ID
txtCategory

Table2 -- Parent
Table2ID
txtCategory
intTable1ID

Table3 -- child
Table3ID
txtData
intTable2ID

This will return just the parent and child information:

SELECT T3.Table3ID, T3.txtData, T2.txtCategory
FROM Table3 T3
    INNER JOIN Table2 T2 ON
    T2.Table2ID = T3.intTable2ID

This will also give grandparent information:

SELECT T3.Table3ID, T3.txtData, T2.txtCategory txtCategory2, T1.txtCategory
txtCategory1
FROM Table3 T3
    INNER JOIN Table2 T2 ON
    T2.Table2ID = T3.intTable2ID
    INNER JOIN Table1 T1 ON
    T1.Table1ID = T2.intTable1ID    

You can make this chain as long or as short as you want.

regards
David Cameron
nOw.b2b
dcameron@i...

-----Original Message-----
From: sean hayes [mailto:sean@b...]
Sent: Tuesday, 27 November 2001 9:04 AM
To: sql language
Subject: [sql_language] Looping and variables


Could someone please describe what they feel the best approach for the 
following problem is.  I have a single table that houses categorized 
products in it.  It however is categorized in the sense that it knows it's 
parent, but not it's grandparent record.  I want to drill up as many 
levels until I get to it's top level category.  So I have a single table 
that has all the info, I want to get out of it the product detail which is 
readily available but also the top level category.  I know this is generic 
but if this sounds like something you might be familiar with I will be 
happy to provide all the details you might need.  Thank you.
Sean Hayes



  Return to Index