ELI5: Explain Like I'm 5

Hierarchical and recursive queries in SQL

Hierarchical and recursive queries in SQL are ways of asking questions about data that is organized in a hierarchy, like a family tree. For example, a hierarchical query might ask who the grandparents of a certain person are, or what their great-grandchildren are. A recursive query might ask how many generations back a certain ancestor is.

Hierarchical queries are usually used to find out or display information about how elements of one table in a database are related to each other. For example, you might have a database that stores information about people in a family, such as the names of people, their parents, and other relatives. A hierarchical query might be used to show all of the family members that someone is related to.

Recursive queries are used to find out more details about a particular ancestor or family member. For example, you might use a recursive query to find out how many generations back a certain ancestor is, or to find out the name of the oldest ancestor in a family tree.