Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 23rd, 2004, 03:41 AM
Authorized User
 
Join Date: Apr 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default multiple self-join

I have a table with this structure and content

IdA Name FK_Ida
1 A 1
2 Aa 1
3 Ab 1
4 Aaa 2
5 Abb 2
6 Acc 3
7 Add 3

I want to use a SQL-query to get this result

A Aa Aaa
A Aa Abb
A Ab Acc
A Ab Add


I've tryed this:


SELECT a.Name as ParentCategory, b.Name
FROM table as a right JOIN table AS b
  ON a.ida = b.fk_ida


Select a.Name as ParentCategory, b.Name
From table a, table b
Where a.ida = b.fk_ida


But both of them give me just the "top level" and "sub level" but not the "sub sub level"

Can someone help me with a correct SQL-question to get all of the levels in a table like that?

Thank you

//Matte

 
Old April 23rd, 2004, 04:24 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

It sounds like you have the same problem as this post: http://p2p.wrox.com/topic.asp?TOPIC_ID=7599

does that help?
 
Old April 23rd, 2004, 05:20 AM
Authorized User
 
Join Date: Apr 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Select a.Name , b.Name , c.Name
From table a, table b , table c
Where a.ida = b.fk_ida
AND b.ida = c.fk_ida






Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple Self Join w/Dynamic Level Hierarchy LiamLiamLiam SQL Language 0 August 17th, 2007 10:21 AM
Inner join query with multiple tables.. rupen Access 2 April 9th, 2007 11:16 AM
Insert multiple records in a Inner Join Table rylemer Access 1 August 22nd, 2004 07:44 AM
Insert multiple records in a Inner Join Table rylemer Access VBA 0 July 19th, 2004 03:54 PM
Inner Join multiple tables qwprince Classic ASP Databases 5 July 23rd, 2003 02:33 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.