小编典典

如何在此查询中修复联接

sql

我想我正在解决这个问题,但是遇到了另一个障碍,并且不知道如何解决它

此查询有什么问题-
只需获取通用的“您有一个错误”,它指向联接,但我不知道如何解决它。我想要对customer_address_entity进行联接,因为它具有我需要在其中一条select语句中使用的另一个唯一ID。

    select c.*, 
(
select caet.value 
from customer_address_entity_test caet 
where cae.entity_id = caet.value_id 
and caet.attribute_id = 23
) as test,
(
select caev.value 
from customer_address_entity_varchar caev 
where caet.entity_id = caev.entity_id 
and caev.attribute_id = 23
) as two
from customer_entity c where store_id = 15
join customer_address_entity cae on c.`entity_id` = cae.`parent_id`;

阅读 146

收藏
2021-04-14

共1个答案

小编典典

首先,您的代码如下所示:

select  c.*, 
        (
            select  caet.value 
            from    customer_address_entity_test caet 
            where   cae.entity_id = caet.value_id 
                    and caet.attribute_id = 23
        ) as test,
        (
            select  莽aev.value 
            from    customer_address_entity_varchar caev 
            where   caet.entity_id = caev.entity_id 
                    and caev.attribute_id = 23
        ) two
join customer_address_entity cae on c.`entity_id` = cae.`parent_id`
from customer_entity c where store_id = 8

很明显,您在FROM之前有JOIN。

其次,您有一个带有unicode字符的莽aev。我不知道这是否有意。

可能这将工作:

select  c.*, 
        (
            select  caet.value 
            from    customer_address_entity_test caet 
            where   cae.entity_id = caet.value_id 
                    and caet.attribute_id = 23
        ) as test,
        (
            select  caev.value 
            from    customer_address_entity_varchar caev 
            where   caet.entity_id = caev.entity_id 
                    and caev.attribute_id = 23
        ) as two
from customer_entity c
join customer_address_entity cae on c.`entity_id` = cae.`parent_id`
where store_id = 8

我在“两个”同盟旁边添加了一个“ as”,只是为了使您的代码一致。

2021-04-14