**Use Case:** When you need to identify items-vendor pairs where the price on the latest PO for that vendor and item does not match vendor's listed price
```sql
SELECT
I.id AS item_id,
I.itemid AS item_name,
IV.vendor AS vendor_id,
IV.vendorcost,
latest_purchaseorder.rate AS last_purchase_price
FROM
item I
INNER JOIN inventoryItemItemVendor IV ON IV.item = I.id
INNER JOIN (
SELECT
item,
entity,
rate,
transaction
FROM
(
SELECT
TL.item AS item,
T.entity AS entity,
TL.rate AS rate,
T.id AS transaction,
ROW_NUMBER() OVER (
PARTITION BY TL.item,
T.entity
ORDER BY
T.trandate DESC,
T.id DESC
) AS rn
FROM
transactionline TL
INNER JOIN transaction T ON T.id = TL.transaction
WHERE
T.recordtype = 'purchaseorder'
)
WHERE
rn = 1
) latest_purchaseorder ON latest_purchaseorder.item = I.id
AND latest_purchaseorder.entity = IV.vendor
WHERE
I.isinactive = 'F' AND IV.vendorcost <> latest_purchaseorder.rate
```