Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

How do you make a SELECT that gets the items in the correct order?

The point of the solution here is so you can simply go `SELECT * FROM list ORDER BY pos` and have the correct order.



  with recursive todo_list_sorted as (
  	select
  		*
  	from
  		todo_list tl1 where prev_id is null
  	union all
  	select
  		tl1.*	
  	from
  		todo_list tl1
  	join
  		todo_list_sorted tl2 on tl1.prev_id = tl2.id
  )
  select * from todo_list_sorted


You don't. You order it on the client!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: