﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
26634	Add the ability to do subselects for querying versioned data	Darren Hobbs	nobody	"I have versioned data of the form:

id (autogenerate)
ref (uuid)
version (integer)

Each 'save' inserts a new version with the same ref and (version+1) version number.
I'd like an easy way to say 'give me the latest versions' (ie. distinct on refs, with max(version)).

The SQL looks like this:

select * from myapp_project where
id in (SELECT id from myapp_project p WHERE p.version = (SELECT max(version) FROM myapp_project p1 WHERE p1.ref = p.ref))

I had to use extra(where=[maxids]) to achieve this*.

*Where maxids = ""id in (SELECT id from myapp_project p WHERE p.version = (SELECT max(version) FROM myapp_project p1 WHERE p1.ref = p.ref))""

Stackoverflow discussion here:
http://stackoverflow.com/questions/37303010/what-is-the-django-way-of-doing-a-subselect"	Uncategorized	new	Uncategorized	1.8	Normal		QuerySet.extra		Unreviewed	0	0	0	0	0	0
