vendredi 4 décembre 2015

Select newest version from table (MS SQL Server, SQLite)

Let's say, I have the following table:

ID | UID | Version | Content
---+-----+---------+-----------------------------
 1 |   1 |       1 | Something
 2 |   1 |       2 | Something (changed)
 3 |   2 |       1 | Alice has a cat
 4 |   2 |       2 | Alice has a cat and a dog
 5 |   2 |       3 | Alice has a cat and a canary

I need to create query, which will return all objects, but only with newest version, so in this case:

ID | UID | Version | Content
---+-----+---------+-----------------------------
 2 |   1 |       2 | Something (changed)
 5 |   2 |       3 | Alice has a cat and a canary

Since SQL dialects differ, I'll be running this query on MS Sql Server 2008 and SQLite 3.

How can I achieve that?

Aucun commentaire:

Enregistrer un commentaire