1054 - Unknown column 'p2c.categories_id' in 'where clause'

SELECT distinct c.categories_id, c.categories_status, c.parent_id, c.master_id, case true when cd.categories_name LIKE '%p1240%' then 0 else 999 end as 'wertigkeit' from products as p inner join products_description as pd on p.products_id = pd.products_id and p.products_status = "1" inner join products_to_categories as c2d on p.products_id=c2d.products_id inner join categories_description as cd on c2d.categories_id=cd.categories_id inner join categories as c on cd.categories_id = c.master_id inner join categories as cm on cm.categories_id = c.master_id and c.categories_status = "1" WHERE c.categories_status = '1' AND cd.language_id = '2' AND pd.language_id = '2' AND p2c.categories_id = '0' AND p.group_permission_1=1 AND ( ( cd.categories_description LIKE ('%p1240%') or cd.categories_description LIKE ('%p1240%') or pd.products_short_description_shop LIKE ('%p1240%') or pd.products_short_description_shop LIKE ('%p1240%') OR cd.categories_name LIKE ('%p1240%') OR p.products_model LIKE ('%p1240%') ) ) ORDER BY wertigkeit, cd.categories_name

[XT SQL Error]