Friday, 23 August 2013

Select only the latest version of the data with SQL join

Select only the latest version of the data with SQL join

I have two tables one containg offer information and the other containg
products something like this:
OFFER PRODUCTS
ID Number Version poID offer_id Product
how_many
==========================
========================================
1 123 1 1 1 Apple 1
2 123 2 2 1 Banana 2
3 124 1 3 1 Orange 1
4 2 Apple 1
5 2 Banana 2
6 2 Orange 2
7 2 Kiwi 1
8 3 Apple 2
9 3 Banana 3
I would like a list of how many products that are currently offered. Since
OFFER(id = 2) is an update of (id = 1) only (id = 2) should be counted.
How should I best query this?

No comments:

Post a Comment