/* Using an inline view,          */ 
/* 1) The traditional way, and    */ 
/* 2) Creating a CTE using "with" */


/* 1 */
SELECT o.payment_num, o.vendor, o.amount, o.pay_date, description
  FROM payment o JOIN
       (SELECT vendor, MAX(pay_date) max_date 
	      FROM payment 
	     GROUP BY vendor)  i
    ON o.vendor   = i.vendor
 WHERE o.pay_date = i.max_date;


/* 2 */
WITH i as (SELECT vendor, MAX(pay_date) max_date 
	         FROM payment 
	        GROUP BY vendor)  
SELECT o.payment_num, o.vendor, o.amount, o.pay_date, description
  FROM payment o JOIN i
    ON o.vendor   = i.vendor
 WHERE o.pay_date = i.max_date;