0

我有这样的查询

SELECT
    tbl_products.*,
    GROUP_CONCAT(tags.name)
FROM
    tbl_page_collections_products,
    (SELECT page_collection_name as name 
       FROM tbl_page_collections 
       LEFT JOIN tbl_pages ON tbl_page_collections.page_id = tbl_pages.page_id 
       WHERE tbl_pages.page_name LIKE '%friends%') tags
    LEFT JOIN tbl_page_collections 
      ON tbl_page_collections.page_collection_id = tbl_page_collections_products.colID 
    LEFT JOIN tbl_pages 
      ON tbl_page_collections.page_id = tbl_pages.page_id 
    LEFT JOIN tbl_products 
      ON tbl_products.product_id = tbl_page_collections_products.product
   WHERE
    tbl_pages.page_name LIKE '%friends%'

我得到的错误是Unknown column 'tbl_page_collections_products.colID in on clause,但是当子查询不存在并且该列存在于该表中时,我没有得到该错误。

有什么矛盾的吗?

4

1 回答 1

0

tbl_page_collections_products 不在您的子查询 from 子句中。也许这就是你想要的:

SELECT
tbl_products.*,
GROUP_CONCAT(tags.name)
FROM
tbl_products,
(SELECT page_collection_name as name 
   FROM tbl_page_collections
   ,tbl_page_collections_products
   LEFT JOIN tbl_pages ON tbl_page_collections.page_id = tbl_pages.page_id 
   WHERE tbl_pages.page_name LIKE '%friends%') tags
LEFT JOIN tbl_page_collections 
  ON tbl_page_collections.page_collection_id = tbl_page_collections_products.colID 
LEFT JOIN tbl_pages 
  ON tbl_page_collections.page_id = tbl_pages.page_id 
LEFT JOIN tbl_products 
  ON tbl_products.product_id = tbl_page_collections_products.product
WHERE
 tbl_pages.page_name LIKE '%friends%'
于 2012-06-08T14:24:36.647 回答