Syspect
Syspect

Reputation: 921

#1054 - Unknown column - given error, whereas the column DOES exist

INSERT INTO  `database_name`.`table_3` (
    `value_id` ,
    `entity_type_id` ,
    `attribute_id` ,
    `store_id` ,
    `entity_id` ,
    `value`
)
SELECT NULL, 4, attribute_id_values.attribute_id, 0, table_3.entity_id, table_1.value
FROM table_4
    INNER JOIN table_1 ON table_3.entity_id = table_1.entity_id
    INNER JOIN table_1 ON table_2.value_id = table_1.value_id AND table_2.store_id = 0 AND table_2.position = 0
    CROSS JOIN
    (
       SELECT 85 AS attribute_id
    UNION
       SELECT 86 AS attribute_id
    UNION
       SELECT 87 AS attribute_id
    ) AS attribute_id_values
    WHERE table_3.sku IN ('20710','3280401s')
ON DUPLICATE KEY UPDATE table_3.value = table_1.value

The field list:

enter image description here

So, I am getting this error:

#1054 - Unknown column 'table_3.entity_id' in 'field list'

And I surely don't see why this problem occurs, whereas I DO have the column in the certain table... Any suggestions?

Upvotes: 1

Views: 77

Answers (1)

Mike Perrenoud
Mike Perrenoud

Reputation: 67948

The issue is table_3 is nowhere in the FROM list (i.e. FROM or JOIN).

I think you were maybe trying to do this:

SELECT NULL, 4, attribute_id_values.attribute_id, 0, table_3.entity_id, table_1.value
FROM table_1
    INNER JOIN table_3 ON table_3.entity_id = table_1.entity_id
    INNER JOIN table_2 ON table_2.value_id = table_1.value_id AND table_2.store_id = 0 AND table_2.position = 0
    CROSS JOIN
    (
       SELECT 85 AS attribute_id
    UNION
       SELECT 86 AS attribute_id
    UNION
       SELECT 87 AS attribute_id
    ) AS attribute_id_values
    WHERE table_3.sku IN ('20710','3280401s')
ON DUPLICATE KEY UPDATE table_3.value = table_1.value

Upvotes: 1

Related Questions