· 6 years ago · Mar 19, 2019, 06:24 PM
1-- id_arp is foreign key for Cast table
2-- ID is primary key for Arp table
3-- if doesn't have unused ID, return NULL,NULL
4create temp view if not EXISTS cst_unused_id as
5select
6(select
7 (select t1.ID from Arp where t1.sfp_src = 1) as free_id
8 FROM Arp AS t1 left outer join 'Cast' as c1 on t1.ID = c1.id_arp WHERE c1.id_arp is null
9 GROUP BY free_id HAVING free_id is not null) as id_0,
10(select
11 (select t2.ID from Arp where t2.sfp_src = 2) as free_id
12 FROM Arp AS t2 left outer join 'Cast' as c2 on t2.ID = c2.id_arp WHERE c2.id_arp is null
13 GROUP BY free_id HAVING free_id is not null) as id_1