Consider a DB with two tables:
PurchaseOrder
PO_ID as int
Username as varchar
(etc)
Items
Item_ID as int
PO_ID as int
Description as varchar
(etc)
What I want to do is the following
Select * from items
where description is distinct
and item_id is maximum item_id for the user and description
and username is 'myUser'
In other words, create a table that has as many rows as there are distinct items that the user has ever ordered and fill in the rest of the row with the data from the most recent (Item_ID monotonically increases) other (etc) data for the item.
Just to make this clear, here is an example (Items table only - assume that we have already filtered for 'myUser'):
Item_ID Description Other columns
1 gloves etc1
2 boots etc2
3 gloves etc3
after the query, the resultant table should be:
Item_ID Description Other columns
2 boots etc2
3 gloves etc3
The following query:
SELECT DISTINCT description
FROM items, purchaseorder
WHERE purchaseorder.username='myUser' and
items.id_po=purchaseorder.id_po
is, I think, part of the answer as it returns a table with the distinct items ordered by the specified user. However, I have been unable to associate the (etc) data of the most recent acquisition of the described item to the description.
Your help is appreciated.
Thanks.
----
Gerry Roston
gerry@pairofdocs.net
PurchaseOrder
PO_ID as int
Username as varchar
(etc)
Items
Item_ID as int
PO_ID as int
Description as varchar
(etc)
What I want to do is the following
Select * from items
where description is distinct
and item_id is maximum item_id for the user and description
and username is 'myUser'
In other words, create a table that has as many rows as there are distinct items that the user has ever ordered and fill in the rest of the row with the data from the most recent (Item_ID monotonically increases) other (etc) data for the item.
Just to make this clear, here is an example (Items table only - assume that we have already filtered for 'myUser'):
Item_ID Description Other columns
1 gloves etc1
2 boots etc2
3 gloves etc3
after the query, the resultant table should be:
Item_ID Description Other columns
2 boots etc2
3 gloves etc3
The following query:
SELECT DISTINCT description
FROM items, purchaseorder
WHERE purchaseorder.username='myUser' and
items.id_po=purchaseorder.id_po
is, I think, part of the answer as it returns a table with the distinct items ordered by the specified user. However, I have been unable to associate the (etc) data of the most recent acquisition of the described item to the description.
Your help is appreciated.
Thanks.
----
Gerry Roston
gerry@pairofdocs.net