I have some code I've been using in SQL Server to generate a closure table from another table that has just the direct parent/child relationships, I can run very simple queries against this to determine lineage. Now I am needing to do all this in mySQL, but I am having trouble with the recursive querying to generate the closure table...
My original SQL server query is
WHILE @@ROWCOUNT>0
INSERT INTO [ClosureTable] ([Ancestor], [Descendent])
SELECT distinct [Parent],[tc].[Descendent]
FROM
[RelationshipTable]
INNER JOIN [ClosureTable] as tc
ON [Child]COLLATE DATABASE_DEFAULT =
[tc].[Ancestor]COLLATE DATABASE_DEFAULT
LEFT OUTER JOIN [ClosureTable] As tc2
ON [Parent]COLLATE DATABASE_DEFAULT =
[tc2].[Ancestor] COLLATE DATABASE_DEFAULT
AND [tc].[Descendent]COLLATE DATABASE_DEFAULT =
[tc2].[Descendent]COLLATE DATABASE_DEFAULT
My first problem is finding a substiture for @@ROWCOUNT... but perhaps recursive queries are completely different in mySQL? I've also checked out Bill Karwin's presentation
PS. The "COLLATE DATABASE_DEFAULT" was something I needed due to performance issues..
Thanks.