I am currently working on a simple revision system that enables me to store multiple versions of a single file, which works fine so far.
Table structure is as follows (obsolete columns removed for the sake of brevity):
file_id file_revision file_parent file_name
--------------------------------------------------------
1 1 0 foo.jpg
2 2 1 foorevised.jpg
3 3 1 anotherrevision.jpg
Where:
file_id
is the primary key, which auto incrementsfile_revision
stores the revision number, defaulting to1
when it's the firstfile_parent
is the top level parent of revision, defaulting to0
when first.file_name
being the file name.
The problem:
- Preferably using a single query I want to retrieve all files...
- But only the latest revision of each file...
- ... when only one revision is stored (original), this one should be retrieved.
Any pointers are greatly appreciated. Thanks in advance.