June 2010
Intermediate to advanced
328 pages
7h 51m
English
A tree is a tree—how many more do you need to look at?
Suppose you work as a software developer for a famous website for science and technology news.
This is a modern website, so readers can contribute comments and even reply to each other, forming threads of discussion that branch and extend deeply. You choose a simple solution to track these reply chains: each comment references the comment to which it replies.
| Trees/intro/parent.sql | |
| | CREATE TABLE Comments ( |
| | comment_id SERIAL PRIMARY KEY, |
| | parent_id BIGINT UNSIGNED, |
| | comment TEXT NOT NULL, |
| | FOREIGN KEY (parent_id) REFERENCES Comments(comment_id) |
| | ); |
It soon becomes clear, however, that it’s hard to retrieve a long chain of replies ...
Read now
Unlock full access