I have a list of 463 CARRIER_CD. I am attempting to retrieve the most current BILL_DT for each of the 463 CARRIER_CD.
I have uploaded the 463 unique CARRIER_CD to a database named edw_sbx_bt the table name is jjenkins_carriers.
The BILL_DT is in a database named edw_ar_fl and table named ARTBASE. I wrote the query below in hopes of returning a single row of data including CARRIER_CD, BILL_DT, and BILL_AMT for the most recent BILL_DT associated with each of the unique CARRIER_CD. However, the query returns 408+ million rows. Any help would be appreciated.
SELECT edw_ar_fl.ARTBASE.CARRIER_CD, edw_ar_fl.ARTBASE.BILL_DT, edw_ar_fl.ARTBASE.BILL_AMT FROM edw_ar_fl.ARTBASE JOIN edw_sbx_bt.jjenkins_carriers ON edw_ar_fl.ARTBASE.CARRIER_CD = edw_sbx_bt.jjenkins_carriers.CARRIER_CD AND edw_ar_fl.ARTBASE.BILL_DT = (select max(edw_ar_fl.ARTBASE.BILL_DT) where edw_ar_fl.ARTBASE.CARRIER_CD = edw_sbx_bt.jjenkins_carriers.CARRIER_CD)