I have a table with 3 fields namely id,filename and prev\_id used for storing uploaded files

```
Id |  filename | prev_id
---------------------------
1  |  file1    | NULL
2  |  file2    | 1
3  |  file3    | 2
4  |  file4    | NULL
5  |  file5    | 4
6  |  file6    | 5

```

file3 is the latest uploaded file while others are the previous one noted with prev\_id. I want a query to list the previous files of file3. Like wise another newly uploaded file is file6 . So when 

<http://www.sqlfiddle.com/#!9/0e88c0/1>

Expected Output

---

List of previous files of file3

```
Id |  filename 
------------
1  |  file1    
2  |  file2    

```

List of previous files of file6

```
Id |  filename 
------------
4  |  file4    
5  |  file5    

```