SHARE
TWEET

Untitled

a guest Mar 21st, 2019 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Id |  filename | prev_id
  2. ---------------------------
  3. 1  |  file1    | NULL
  4. 2  |  file2    | 1
  5. 3  |  file3    | 2
  6. 4  |  file4    | NULL
  7. 5  |  file5    | 4
  8. 6  |  file6    | 5
  9.      
  10. Id |  filename
  11. ------------
  12. 1  |  file1    
  13. 2  |  file2
  14.      
  15. Id |  filename
  16. ------------
  17. 4  |  file4    
  18. 5  |  file5
  19.      
  20. id  fname   prev_id
  21. 1   file1   (null)
  22. 2   file2   1
  23. 3   file3   2
  24. 4   file4   (null)
  25.      
  26. select a.*
  27. from test_table a
  28. inner join test_table b on b.fname ='file3'
  29.     and a.prev_id  <= b.prev_id
  30.      
  31. select t1.id, t1.fname, @pv := t1.prev_id prev_id
  32. from (select * from test_table order by id desc) t1
  33. join (select @pv := 3) tmp  // 3 is the id of file3
  34. where t1.id = @pv;
  35.      
  36. select (@pv := t1.prev_id) id, t1.fname
  37. from (select * from test_table order by id desc) t1
  38. join (
  39.      select @pv := (
  40.             select t4.prev_id
  41.             from test_table t4
  42.             where t4.id = 3
  43.           )
  44. ) tmp
  45. where t1.id = @pv;
  46.      
  47. select * from file where id < 14 ;
  48.      
  49. select * from file where id in (
  50.             select id from file where id < 14
  51.      ) order by id DESC limit 1;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top