2

I want to retrieve the last three children of my parent. Currently the statement reads:

SELECT * 
from replies 
order by rID,rValue 

Because rValue signifies the reply mechanism a null rValue means that is the parent. To allow replies to replies rValue goes x to x.999999 and I was hoping there is some way to retrieve the last three results for each parent. Please hit me up if any further clarification is required.

EDIT: Lets say a limit of 30 thread per page and a maximum of 1000replies per thread would it be a huge strain on the DB just to get all the results then cycle through to the last 3 of each?

Matt
  • 501
  • 3
  • 13

1 Answers1

0

You need common table expression and recursive queries. Take a look at your RDBMS if it supports them.

Pablo Santa Cruz
  • 176,835
  • 32
  • 241
  • 292