I have a table that stores a string specifying user's permissions. I have a column previous
that has a FK to id
in the same table, and this way linking to the previous version of the permissions. What I want to do is create a view that will only show the last of this chain (the most up-to-date one). The original one does not have any previous value set. The table than looks like this:
+-------+-------+------+----------+---------+
| ID | PERMS | USER | PREVIOUS | VERSION |
+-------+-------+------+----------+---------+
| GUID1 | set1 | John | | 1 |
| GUID2 | set2 | Dave | | 1 |
| GUID3 | set3 | John | GUID1 | 2 |
| GUID4 | set4 | Phil | | 1 |
| GUID5 | set5 | John | GUID3 | 3 |
| GUID6 | set6 | Dave | GUID2 | 2 |
and so on...
What I want to get from the view is just John's set5, Dave's set6 and Phil's set4. Google search didn't bring anything useful, surprisingly...
Thanks in advance for any help!