insert into creditcardstypes (idcreditcards,idcardtype) select * from ( select cc.idcreditcards,(select idcardtype from cardtypes ct where ct.cardtypedesc='cash back') idcardtype_X from CardFilters cf left outer join creditcards cc on cf.cardname=cc.creditcardsname where cc.idcreditcards is not null and cf.Cash_Back is not null union all select cc.idcreditcards,(select idcardtype from cardtypes ct where ct.cardtypedesc='Welcome Bonus') idcardtype_X from CardFilters cf left outer join creditcards cc on cf.cardname=cc.creditcardsname where cc.idcreditcards is not null and cf.Welcome_Bonus is not null union all select cc.idcreditcards,(select idcardtype from cardtypes ct where ct.cardtypedesc='Free For Life') idcardtype_X from CardFilters cf left outer join creditcards cc on cf.cardname=cc.creditcardsname where cc.idcreditcards is not null and cf.Free_for_Life is not null union all select cc.idcreditcards,(select idcardtype from cardtypes ct where ct.cardtypedesc='Travel Card') idcardtype_X from CardFilters cf left outer join creditcards cc on cf.cardname=cc.creditcardsname where cc.idcreditcards is not null and cf.Travel_Card is not null union all select cc.idcreditcards,(select idcardtype from cardtypes ct where ct.cardtypedesc='Premium Card') idcardtype_X from CardFilters cf left outer join creditcards cc on cf.cardname=cc.creditcardsname where cc.idcreditcards is not null and cf.Premium_Card is not null union all select cc.idcreditcards,(select idcardtype from cardtypes ct where ct.cardtypedesc='Etihad Miles') idcardtype_X from CardFilters cf left outer join creditcards cc on cf.cardname=cc.creditcardsname where cc.idcreditcards is not null and cf.Etihad_Miles is not null union all select cc.idcreditcards,(select idcardtype from cardtypes ct where ct.cardtypedesc='Emirate SkyWord') idcardtype_X from CardFilters cf left outer join creditcards cc on cf.cardname=cc.creditcardsname where cc.idcreditcards is not null and cf.Emirate_Skywards is not null union all select cc.idcreditcards,(select idcardtype from cardtypes ct where ct.cardtypedesc='Balance Transfer') idcardtype_X from CardFilters cf left outer join creditcards cc on cf.cardname=cc.creditcardsname where cc.idcreditcards is not null and cf.Balance_Transfer is not null union all select cc.idcreditcards,(select idcardtype from cardtypes ct where ct.cardtypedesc='Fixed Deposit') idcardtype_X from CardFilters cf left outer join creditcards cc on cf.cardname=cc.creditcardsname where cc.idcreditcards is not null and cf.Fixed_Deposit is not null union all select cc.idcreditcards,(select idcardtype from cardtypes ct where ct.cardtypedesc='Islamic Card') idcardtype_X from CardFilters cf left outer join creditcards cc on cf.cardname=cc.creditcardsname where cc.idcreditcards is not null and cf.Islamic_Card is not null union all select cc.idcreditcards,(select idcardtype from cardtypes ct where ct.cardtypedesc='Emarati Cards') idcardtype_X from CardFilters cf left outer join creditcards cc on cf.cardname=cc.creditcardsname where cc.idcreditcards is not null and cf.Emirati_Card is not null union all select cc.idcreditcards,(select idcardtype from cardtypes ct where ct.cardtypedesc='Life Style') idcardtype_X from CardFilters cf left outer join creditcards cc on cf.cardname=cc.creditcardsname where cc.idcreditcards is not null and cf.Life_style is not null union all select cc.idcreditcards,(select idcardtype from cardtypes ct where ct.cardtypedesc='First Year Free') idcardtype_X from CardFilters cf left outer join creditcards cc on cf.cardname=cc.creditcardsname where cc.idcreditcards is not null and cf.First_Year_Free is not null union all select cc.idcreditcards,(select idcardtype from cardtypes ct where ct.cardtypedesc='Airport Lounge') idcardtype_X from CardFilters cf left outer join creditcards cc on cf.cardname=cc.creditcardsname where cc.idcreditcards is not null and cf.Airport_Lounge is not null union all select cc.idcreditcards,(select idcardtype from cardtypes ct where ct.cardtypedesc='Fuel Discounts') idcardtype_X from CardFilters cf left outer join creditcards cc on cf.cardname=cc.creditcardsname where cc.idcreditcards is not null and cf.Fuel_Discounts is not null union all select cc.idcreditcards,(select idcardtype from cardtypes ct where ct.cardtypedesc='Movies Discount') idcardtype_X from CardFilters cf left outer join creditcards cc on cf.cardname=cc.creditcardsname where cc.idcreditcards is not null and cf.Movies_Discount is not null union all select cc.idcreditcards,(select idcardtype from cardtypes ct where ct.cardtypedesc='Easy Cash') idcardtype_X from CardFilters cf left outer join creditcards cc on cf.cardname=cc.creditcardsname where cc.idcreditcards is not null and cf.Easy_Cash is not null union all select cc.idcreditcards,(select idcardtype from cardtypes ct where ct.cardtypedesc='0% Balance Transfer') idcardtype_X from CardFilters cf left outer join creditcards cc on cf.cardname=cc.creditcardsname where cc.idcreditcards is not null and cf.Column_0_Balance_Transfer is not null union all select cc.idcreditcards,(select idcardtype from cardtypes ct where ct.cardtypedesc='Dining Offers') idcardtype_X from CardFilters cf left outer join creditcards cc on cf.cardname=cc.creditcardsname where cc.idcreditcards is not null and cf.Dining_Offers is not null union all select cc.idcreditcards,(select idcardtype from cardtypes ct where ct.cardtypedesc='Health Club Memberships') idcardtype_X from CardFilters cf left outer join creditcards cc on cf.cardname=cc.creditcardsname where cc.idcreditcards is not null and cf.Health_Club_Memberships is not null union all select cc.idcreditcards,(select idcardtype from cardtypes ct where ct.cardtypedesc='0% Foreign Transaction Fee') idcardtype_X from CardFilters cf left outer join creditcards cc on cf.cardname=cc.creditcardsname where cc.idcreditcards is not null and cf.Column_0_Foreign_Transaction_Fee is not null union all select cc.idcreditcards,(select idcardtype from cardtypes ct where ct.cardtypedesc='Valet Parking') idcardtype_X from CardFilters cf left outer join creditcards cc on cf.cardname=cc.creditcardsname where cc.idcreditcards is not null and cf.Valet_Parking is not null union all select cc.idcreditcards,(select idcardtype from cardtypes ct where ct.cardtypedesc='Golf Benefits') idcardtype_X from CardFilters cf left outer join creditcards cc on cf.cardname=cc.creditcardsname where cc.idcreditcards is not null and cf.Golf_Benefits is not null union all select cc.idcreditcards,(select idcardtype from cardtypes ct where ct.cardtypedesc='Concierge Service') idcardtype_X from CardFilters cf left outer join creditcards cc on cf.cardname=cc.creditcardsname where cc.idcreditcards is not null and cf.Concierge_Service is not null union all select cc.idcreditcards,(select idcardtype from cardtypes ct where ct.cardtypedesc='Free Travel Insurance') idcardtype_X from CardFilters cf left outer join creditcards cc on cf.cardname=cc.creditcardsname where cc.idcreditcards is not null and cf.Free_Travel_Insurance is not null union all select cc.idcreditcards,(select idcardtype from cardtypes ct where ct.cardtypedesc='Airport Meet & Greet') idcardtype_X from CardFilters cf left outer join creditcards cc on cf.cardname=cc.creditcardsname where cc.idcreditcards is not null and cf.Airport_Meet_Greet is not null union all select cc.idcreditcards,(select idcardtype from cardtypes ct where ct.cardtypedesc='Airport Pick-Up / Drop') idcardtype_X from CardFilters cf left outer join creditcards cc on cf.cardname=cc.creditcardsname where cc.idcreditcards is not null and cf.Airport_Pick_Up_Drop is not null union all select cc.idcreditcards,(select idcardtype from cardtypes ct where ct.cardtypedesc='Roadside Assistance') idcardtype_X from CardFilters cf left outer join creditcards cc on cf.cardname=cc.creditcardsname where cc.idcreditcards is not null and cf.Roadside_Assistance is not null union all select cc.idcreditcards,(select idcardtype from cardtypes ct where ct.cardtypedesc='Flexible Payments') idcardtype_X from CardFilters cf left outer join creditcards cc on cf.cardname=cc.creditcardsname where cc.idcreditcards is not null and cf.Flexible_Payments is not null union all select cc.idcreditcards,(select idcardtype from cardtypes ct where ct.cardtypedesc='Amazon Prime Membership') idcardtype_X from CardFilters cf left outer join creditcards cc on cf.cardname=cc.creditcardsname where cc.idcreditcards is not null and cf.Amazon_Prime_Membership is not null union all select cc.idcreditcards,(select idcardtype from cardtypes ct where ct.cardtypedesc='Agoda Offer') idcardtype_X from CardFilters cf left outer join creditcards cc on cf.cardname=cc.creditcardsname where cc.idcreditcards is not null and cf.Agoda_Offer is not null union all select cc.idcreditcards,(select idcardtype from cardtypes ct where ct.cardtypedesc='Avis Car Rental') idcardtype_X from CardFilters cf left outer join creditcards cc on cf.cardname=cc.creditcardsname where cc.idcreditcards is not null and cf.Avis_Car_Rental is not null union all select cc.idcreditcards,(select idcardtype from cardtypes ct where ct.cardtypedesc='Accident Insurance') idcardtype_X from CardFilters cf left outer join creditcards cc on cf.cardname=cc.creditcardsname where cc.idcreditcards is not null and cf.Accident_Insurance is not null union all select cc.idcreditcards,(select idcardtype from cardtypes ct where ct.cardtypedesc='Salam Points') idcardtype_X from CardFilters cf left outer join creditcards cc on cf.cardname=cc.creditcardsname where cc.idcreditcards is not null and cf.salam_points is not null union all select cc.idcreditcards,(select idcardtype from cardtypes ct where ct.cardtypedesc='Protection Benefits') idcardtype_X from CardFilters cf left outer join creditcards cc on cf.cardname=cc.creditcardsname where cc.idcreditcards is not null and cf.Protection_Benefits is not null union all select cc.idcreditcards,(select idcardtype from cardtypes ct where ct.cardtypedesc='30% discount on Emaar Attraction') idcardtype_X from CardFilters cf left outer join creditcards cc on cf.cardname=cc.creditcardsname where cc.idcreditcards is not null and cf.Column_30_discount_on_Emaar_Attraction is not null union all select cc.idcreditcards,(select idcardtype from cardtypes ct where ct.cardtypedesc='Talabat Benefits') idcardtype_X from CardFilters cf left outer join creditcards cc on cf.cardname=cc.creditcardsname where cc.idcreditcards is not null and cf.Talabat_Benefits is not null ) aa -- where aa.idcardtype_X is null