ALTER TABLE `apw_Cart` ADD `hasSponsorship` ENUM( 'y', 'n' ) NULL DEFAULT NULL AFTER `roleId` , ADD INDEX ( `hasSponsorship` ); -- UPDATE apw_Cart SET hasSponsorship = NULL; UPDATE apw_Cart AS c SET c.hasSponsorship = IFNULL( ( SELECT 'y' FROM apw_CartItem AS ci WHERE ci.cartId = c.id AND ci.cartItemType = 'Sponsor_Category_' LIMIT 1 ), 'n') WHERE c.transactionId IS NOT NULL AND c.hasSponsorship IS NULL;