简体   繁体   中英

How do I fix the join in this query

I think I am closing in on this one, but ran into another snag and have no idea how to fix it

What is wrong with this query - just get the generic "you have an error", it is pointing to the join, but I don't know how to fix it. I want the join on the customer_address_entity because it has the other unique id that I need to use in one of the select statements.

    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`;

First of all your code looks like this:

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

It is obvious that you have the JOIN before the FROM.

Secondly, you have a çaev which has a unicode character. I don't know if this is intended.

Probably this will work:

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

I have added an 'as' next to the 'two' allias only to make your code consistent.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM