我正在尝试使用INNER JOIN
语法转换以下SQL查询以减少执行时间但我在实现OR
时遇到问题(CASES)
原始SQL:
SELECT DISTINCT c.id, c.couponid, c.branchid, c.chainid
FROM `users_roles` a, `field_data_field_ypefthinos` b, `custom_redemptions` c, `field_data_field_chain_manager` e, `field_data_field_node_tax_inception` f, `field_data_field_brand_manager` j, `field_data_field_brand_node_ref` k, `field_data_field_product_ref` i, `field_data_field_company_manager` z, `field_data_field_brand_company` t
WHERE
(a.rid = 4
AND a.uid = ?
AND b.field_ypefthinos_uid = a.uid
AND b.entity_id = c.branchid)
OR
(a.rid = 5
AND a.uid = ?
AND e.field_chain_manager_uid = a.uid
AND e.entity_id = f.entity_id
AND f.field_node_tax_inception_tid = c.chainid)
OR
(a.rid = 9
AND a.uid = ?
AND j.field_brand_manager_uid = a.uid
AND j.entity_id = k.field_brand_node_ref_nid
AND k.entity_id = i.field_product_ref_nid
AND i.entity_id = c.couponid)
OR
(a.rid = 6
AND a.uid = ?
AND z.field_company_manager_uid = a.uid
AND z.entity_id = t.field_brand_company_nid
AND t.entity_id = k.field_brand_node_ref_nid
AND k.entity_id = i.field_product_ref_nid
AND i.entity_id = c.couponid)
在转换过程中:
SELECT DISTINCT c.id, c.couponid, c.branchid, c.chainid
FROM `custom_redemptions` AS c
(INNER JOIN `field_data_field_ypefthinos` as b
ON b.entity_id = c.branchid
INNER JOIN `users_roles` as a
ON b.field_ypefthinos_uid = a.uid
WHERE a.rid = 4
AND a.uid = 351)
OR
(INNER JOIN `field_data_field_node_tax_inception` AS f
ON f.field_node_tax_inception_tid = c.chainid
INNER JOIN `field_data_field_chain_manager` AS e
ON f.entity_id = e.entity_id
INNER JOIN `users_roles` AS a
ON e.field_chain_manager_uid = a.uid
WHERE a.rid = 5
AND a.uid = 351)
OR
(INNER JOIN `field_data_field_product_ref` AS i
ON i.entity_id = c.couponid
INNER JOIN `field_data_field_brand_node_ref` AS k
ON k.entity_id = i.field_product_ref_nid
INNER JOIN `field_data_field_brand_manager` AS j
ON j.entity_id = k.field_brand_node_ref_nid
INNER JOIN `users_roles` AS a
ON j.field_brand_manager_uid = a.uid
WHERE a.rid = 9
AND a.uid = 351)
OR
(INNER JOIN `field_data_field_product_ref` AS i
ON i.entity_id = c.couponid
INNER JOIN `field_data_field_brand_node_ref` AS k
ON k.entity_id = i.field_product_ref_nid
INNER JOIN `field_data_field_brand_company` AS t
ON t.entity_id = k.field_brand_node_ref_nid
INNER JOIN `field_data_field_company_manager` AS z
ON z.entity_id = t.field_brand_company_nid
INNER JOIN `users_roles` AS a
ON z.field_company_manager_uid = a.uid
WHERE a.rid = 6
AND a.uid = 351)
我的代码出了什么问题?
我做错了什么?