我“想”我看到了问题,但不知道如何解决它
得到了一些很棒的/快速的帮助让我的查询理顺,但现在我收到了这个错误: 'where子句'中的未知列'caet.entity_id'
错误出现在第三个select语句中。我想说>>选择 caev .entity_id字段与 caet .entity_id匹配的值。我已经检查过,拼写是正确的,这些字段都在两个表格中。
如果这样做,我还需要另一次加入吗?
select c.*,
(
select caet.value
from customer_address_entity_text 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 = 15
下面的查询显示了我尝试过的内部联接,但仍然出现错误:
select c.*,
(
select caet.value
from customer_address_entity_text 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`
INNER JOIN customer_address_entity_text CAET ON CAET.id = CAEV.id
where store_id = 8
答案 0 :(得分:0)
CAEV不在外部环境中。所以问题是“CAET.id = CAEV.id”。您应该在外部上下文中连接所有表,并在内部上下文中选择。但内部联接不起作用。使用OUTER join。也许你可以在下面使用:
SELECT c.*, caet.value AS test, caev.value AS two
FROM customer_entity AS c INNER JOIN
customer_address_entity AS cae ON c.entity_id = cae.parent_id LEFT OUTER JOIN
customer_address_entity_text AS caet ON cae.entity_id = caet.value_id AND caet.attribute_id = 23 LEFT OUTER JOIN
customer_address_entity_varchar AS caev ON cae.entity_id = caev.entity_id AND caev.attribute_id = 23
WHERE (store_id = 15)