Here is the situation. I have 3 tables, one super type, and two sub types, with a relationship between the sub types:
|----------------| |-------------------| |-------------------|
| Post | | Top_Level | | Comment |
|----------------| |-------------------| |-------------------|
| PK | ID | | PK, FK | Post_ID | | PK, FK | Post_ID |
| | DATE | | | Title | | FK | TopLv_ID |
| | Text | |-------------------| |-------------------|
|----------------|
Each post, either comment or top_lev, is unique, but the entities share some attributes. So, comment and top_lev are sub types of post. That is one portion. Additionally, comments are associated with a top_lev post. This ER diagram illustrates this: http://img11.imageshack.us/img11/9327/sampleer.png
What I am looking for is a list of Top_Level posts ordered by activity on that top_level post, either creation of the top_level post, or a comment on that post.
For example, assume we have the following data:
|------------------------| |------------------| |--------------------|
| Post | | Top_Level | | Comment |
|------------------------| |------------------| |--------------------|
| ID | DATE | Text | | Post_ID | Title | | Post_ID |TopLv_ID |
|----|------------|------| |----------|-------| |----------|---------|
| 1 | 13/03/2008 | shy | | 1 | XYZ | | 2 | 1 |
| 2 | 14/03/2008 | mrj | | 3 | ABC | | 4 | 1 |
| 3 | 15/03/2008 | quw | | 7 | NMO | | 5 | 3 |
| 4 | 16/03/2008 | ksi | |------------------| | 6 | 1 |
| 5 | 17/03/2008 | kso | |--------------------|
| 6 | 18/03/2008 | aoo |
| 7 | 19/03/2008 | all |
|------------------------|
|--------------------------------|
| RESULT |
|--------------------------------|
| ID | DATE | Title | Text |
|----|------------|-------|------|
| 7 | 19/03/2008 | 123 | all |
| 1 | 13/03/2008 | ABC | shy |
| 3 | 15/03/2008 | XYZ | quw |
|--------------------------------|
Can this be done with a single select statement? If so, how?