answered question

answers (1)

pvera
1
Vote
BEST ANSWER  chosen by asker   |  pvera  |  December 24, 2008 02:35 PM
Are you trying to write a data structure and queries for a hierarchy? If yes, what you are trying to do is called a self-join. You have a column with the parent of the record, so if for example it was a table of employees, you have a column called boss with the primary key of the employee record that is the record's boss. Oracle is the only one that lets you do this cleanly, if you want to do it in MySQL or SQL Server you'll have to work around it a little bit.

Comment
cometbus
cometbus  |  December 25, 2008 12:31 AM
Yes, more or less, self join is about the only way I can think to do this. The trouble is, if you look at this like a online family tree that connects everyone to everyone, there is no way to create the key to join on.

So, for example, let's say we could rely on last names as the key to join on. As the system has more and more users, and you want to build a tree of how people are related to each other, you self join on last name, sprinkle in some recursion, and you quickly have the most inefficient set of lookups on the planet.

If I want this to scale in any way, I am going to need a much more robust solution. Myspace does this to a degree, though they mess it up by seeding every account with the same first "friend", making everyone related to everyone. But remove that person, and it gets a little better in how the relations work. I know they use a MS backed data source. I know Oracle has some nice built in tools to do this stuff.

No one has made a library or equivalent for MySQL? How about postgreSQL, I am not objectionable to using that either. I just can not afford to get locked into the Gucci of databases, being Oracle.

Thanks so much for your reply.
pvera
pvera  |  December 25, 2008 12:49 AM
What about artificially creating a key for each individual, like a GUID? This forces them to be unique and gives you something for your self joins.

For the family tree, it would be like a business flow chart where everyone has two bosses, mom and dad. Since each individual has a unique id, that's what goes into the mom and dad fields.
140

ask any question

Top of Page
Buy Mahalo Dollars
WITH CREDIT CARD OR PAYPAL

Please log in to use this function.