select RTRIM(LTRIM(rl.ric)) 'Identifier', case when (rl.code like '%46%' ) THEN 'True' when (rl.code like '%47%' ) THEN 'True' ELSE 'False' END D1, case when (rl.hard_restriction = 1 AND rl.hard_to_borrow=0) THEN 'Restricted' else '' end 'EventType' from restricted_list rl_1 inner join (select id, max(entry_date) as MaxEntryDate from restricted_list rl_2 group by ric) rl_2 on rl_1.ric = rl_2.ric and rl_1.entry_date = rl_2.MaxEntryDate order by rl_1.ric
↧
Joining a table on itself
↧