'How can write the sql for this use case ? I have to execute with recursion

USE CASE

IF strore_id IS > 0 THEN feteh that record along WITH rest of records AND NOT include entity_id = 1425 AND store_id = 0

SQL WHERE criteria

store_id = 1 AND attribute_id = 1 AND entity_id = 1425

CREATE TABLE `eav_categories_varchar` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `store_id` bigint(20) unsigned NOT NULL,
  `entity_id` bigint(20) unsigned NOT NULL,
  `attribute_id` bigint(20) unsigned NOT NULL,
  `value` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `deleted_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `store_id` (`store_id`),
  KEY `entity_id` (`entity_id`),
  KEY `attribute_id` (`attribute_id`),
  CONSTRAINT `eav_categories_varchar_attribute_id_foreign` FOREIGN KEY (`attribute_id`) REFERENCES `eav_attributes` (`id`) ON DELETE CASCADE,
  CONSTRAINT `eav_categories_varchar_entity_id_foreign` FOREIGN KEY (`entity_id`) REFERENCES `categories` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=643 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci

SELECT
  c2.*
FROM
  `categories`
  INNER JOIN `eav_categories_varchar` AS `c2`
    ON `c2`.`entity_id` = `categories`.`id`
WHERE `c2`.`store_id` IN IF((SELECT COUNT(*) FROM eav_categories_varchar WHERE `store_id` = 0) > 0, 0,0)

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source