Solution: Use Alternative Tree Models
You can use any one of the following solutions to work with hierarchical data in SQL. Each has strengths and weaknesses, and any of them might be the right choice for a given application.
Recursive Queries
Some brands of RDBMS implement SQL syntax features to support hierarchies stored in the Adjacency List format. The SQL-99 standard defines recursive query syntax using the WITH keyword followed by a recursive common table expression.
â | âWITHâ RECURSIVE CommentTree |
â | (comment_id, bug_id, parent_id, author, comment_date, âcommentâ, depth) |
â | âASâ ( |
â | âSELECTâ comment_id, bug_id, parent_id, author, comment_date, |
â | âcommentâ, 0 âASâ depth |
â | âFROM ... |
Get SQL Antipatterns, Volume 1 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.