clear markdown compare help best fiddles feedback dbanow.uk a leap of faith?
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 1130798 fiddles created (16557 in the last week).

WITH TABLE1(ID,NUM) AS ( SELECT 1 AS ID,0 AS NUM UNION ALL SELECT 2 AS ID,1 AS NUM UNION ALL SELECT 3 AS ID,1 AS NUM ), TABLE2(ID,DT_OPEN,C_CODE)AS ( SELECT 1,'20070201','432-654' UNION ALL SELECT 1,'20171211','676-865' UNION ALL SELECT 1,'20181005','454-456' UNION ALL SELECT 2,'20070201','234-566' UNION ALL SELECT 2,'20180510','852-543' UNION ALL SELECT 3,'20171211','686-876' UNION ALL SELECT 3,'20180510','759-252' ) select distinct table1.id, table1.num, case when table1.num = 1 then first_value(table2.c_code) over (partition by table2.id order by table2.dt_open) end c_code from table1,table2 where table1.id = table2.id order by 1
id num c_code
1 0
2 1 234-566
3 1 686-876
 hidden batch(es)