Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

Some do support nesting (hierarchical).

If you wanted one query you could have one table that self references itself. Some RDMS support this concept. For example, with SQL Server one can user Common Table Expressions (CTEs) for a hierarchical query.

In your case the Posts would be at Level 0 and then all the comments would be at Level 1.

The other options are 2 queries or a Join with some extra information for every record returned (that others have mentioned).

Example of Hierarchical:

http://stackoverflow.com/questions/14274942/sql-server-cte-and-recursion-examplehttps://stackoverflow.com/questions/14274942/sql-server-cte-and-recursion-example

In the above link, EmpLevel show the level of the nesting (or hierarchy).

Some do support nesting (hierarchical).

If you wanted one query you could have one table that self references itself. Some RDMS support this concept. For example, with SQL Server one can user Common Table Expressions (CTEs) for a hierarchical query.

In your case the Posts would be at Level 0 and then all the comments would be at Level 1.

The other options are 2 queries or a Join with some extra information for every record returned (that others have mentioned).

Example of Hierarchical:

http://stackoverflow.com/questions/14274942/sql-server-cte-and-recursion-example

In the above link, EmpLevel show the level of the nesting (or hierarchy).

Some do support nesting (hierarchical).

If you wanted one query you could have one table that self references itself. Some RDMS support this concept. For example, with SQL Server one can user Common Table Expressions (CTEs) for a hierarchical query.

In your case the Posts would be at Level 0 and then all the comments would be at Level 1.

The other options are 2 queries or a Join with some extra information for every record returned (that others have mentioned).

Example of Hierarchical:

https://stackoverflow.com/questions/14274942/sql-server-cte-and-recursion-example

In the above link, EmpLevel show the level of the nesting (or hierarchy).

added 269 characters in body
Source Link
Jon Raynor
  • 11.8k
  • 32
  • 49

Some do support nesting (hierarchical).

If you wanted one query you could have one table that self references itself. Some RDMS support this concept. For example, with SQL Server one can user Common Table Expressions (CTEs) for a hierarchical query.

In your case the Posts would be at Level 0 and then all the comments would be at Level 1.

The other options are 2 queries or a Join with some extra information for every record returned (that others have mentioned).

Example of Hierarchical:

http://stackoverflow.com/questions/14274942/sql-server-cte-and-recursion-example

In the above link, EmpLevel show the level of the nesting (or hierarchy).

Some do support nesting (hierarchical).

If you wanted one query you could have one table that self references itself. Some RDMS support this concept. For example, with SQL Server one can user Common Table Expressions (CTEs) for a hierarchical query.

In your case the Posts would be at Level 0 and then all the comments would be at Level 1.

The other options are 2 queries or a Join with some extra information for every record returned (that others have mentioned).

Some do support nesting (hierarchical).

If you wanted one query you could have one table that self references itself. Some RDMS support this concept. For example, with SQL Server one can user Common Table Expressions (CTEs) for a hierarchical query.

In your case the Posts would be at Level 0 and then all the comments would be at Level 1.

The other options are 2 queries or a Join with some extra information for every record returned (that others have mentioned).

Example of Hierarchical:

http://stackoverflow.com/questions/14274942/sql-server-cte-and-recursion-example

In the above link, EmpLevel show the level of the nesting (or hierarchy).

Post Migrated Here from stackoverflow.com (revisions)
Source Link
Jon Raynor
  • 11.8k
  • 32
  • 49

Some do support nesting (hierarchical).

If you wanted one query you could have one table that self references itself. Some RDMS support this concept. For example, with SQL Server one can user Common Table Expressions (CTEs) for a hierarchical query.

In your case the Posts would be at Level 0 and then all the comments would be at Level 1.

The other options are 2 queries or a Join with some extra information for every record returned (that others have mentioned).