MySQL Forums
Forum List  »  Newbie

Using joins on the same table
Posted by: Tom Hagen
Date: August 10, 2004 12:31PM

Hello,

I am trying to move some of my applications from MS SQL to My SQL (currently 4.1.8) and have come to a little problem: Can I use the same table twice in Select statement using joins.

Suppose I have got folder hierarchy in a table:
tblFolders (ID, MasterId, Name),
where MasterID points to existing ID in the same table (Parent folder).

How can I make a Select query displaying for each of the folders count of their child folders?

I supposed something like:
Select t1.Name From tblFolders AS t1 Left Outer Join (Select MasterId, Count(*) ChildCount From tblFolders Group By MasterID) as t2 On t1.ID = t2.MasterID

But MySQL says:
ERROR 1064: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use ...

Options: ReplyQuote


Subject
Written By
Posted
Using joins on the same table
August 10, 2004 12:31PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.