vendredi 27 février 2015

SQL Statement intermediate issue

I have a table where lots of products are stored. Each row has 3 columns: ProductID, RevisionID, and Name


I need to make a sql statement to get a list of all the products, but only one for each ProductID.


However many rows can have the same ProductID but incrementing RevisionIDs.


So when getting all the products I need to make sure to only get one of each ProductID, and make sure them rows are the latest RevisionIDs.


SELECT * FROM #TABLE WHERE ProductID is unique AND this products RevisionID is the highest for all the ProductID rows


Aucun commentaire:

Enregistrer un commentaire