SQL for selecting only the last item from a versioned table
- by Jeremy
I have a table with the following structure:
CREATE TABLE items (
id serial not null,
title character varying(255),
version_id integer DEFAULT 1,
parent_id integer,
CONSTRAINT items_pkey PRIMARY KEY (id)
)
So the table contains rows that looks as so:
id: 1, title: "Version 1", version_id: 1, parent_id: 1
id: 2, title:…