select * 
from a right join 
(select max(review_id) as review_id,entity_pk_value,max(created_at) as created_at from review rev group by entity_pk_value) as b
on a.xx=b.entity_pk_value总提示Incorrect table name(select max(review_id) as review_id,entity_pk_value,max(created_at) as created_at from review rev group by entity_pk_value),mysql 子查询怎么用?

解决方案 »

  1.   

    select max(review_id) as review_id,entity_pk_value,max(created_at) as created_at from review rev group by entity_pk_value
    这个是可以正常执行的
      

  2.   

    你的MYSQL版本是多少? MYSQL4.1开始支持子查询。
      

  3.   

    SELECT `e`.*, IFNULL(_table_inchoo_featured_product.value, _table_inchoo_featured_product_default.value) AS `inchoo_featured_product`, IFNULL(_table_product_rank.value, _table_product_rank_default.value) AS `product_rank`, `review_table`.`review_id`, `review_table`.`created_at`, `cat_index`.`position` AS `cat_index_position` FROM `catalog_product_entity` AS `e` LEFT JOIN `catalog_product_entity_int` AS `_table_inchoo_featured_product_default` ON (_table_inchoo_featured_product_default.entity_id = e.entity_id) AND (_table_inchoo_featured_product_default.attribute_id='496') AND _table_inchoo_featured_product_default.store_id=0 LEFT JOIN `catalog_product_entity_int` AS `_table_inchoo_featured_product` ON (_table_inchoo_featured_product.entity_id = e.entity_id) AND (_table_inchoo_featured_product.attribute_id='496') AND (_table_inchoo_featured_product.store_id='1') LEFT JOIN `catalog_product_entity_varchar` AS `_table_product_rank_default` ON (_table_product_rank_default.entity_id = e.entity_id) AND (_table_product_rank_default.attribute_id='497') AND _table_product_rank_default.store_id=0 LEFT JOIN `catalog_product_entity_varchar` AS `_table_product_rank` ON (_table_product_rank.entity_id = e.entity_id) AND (_table_product_rank.attribute_id='497') AND (_table_product_rank.store_id='1') LEFT JOIN ` (select max(review_id) as review_id,entity_pk_value,max(created_at) as created_at from review rev group by entity_pk_value) ` AS `review_table`  ON e.entity_id = review_table.entity_pk_value INNER JOIN `catalog_category_product_index` AS `cat_index` ON cat_index.product_id=e.entity_id AND cat_index.store_id='1' AND cat_index.visibility IN(2, 4) AND cat_index.category_id='2' WHERE (IFNULL(_table_inchoo_featured_product.value, _table_inchoo_featured_product_default.value) = '1') LIMIT 3
      

  4.   

    语句比较长,CSDN竟不能换行?
    我想把重点部分标出来,CSDN也不太方便......@ACMAIN_CHM朋友
    上述语句中[color=#FF0000][color]部分是我想要标出来的语句,就是这里有问题
      

  5.   

    LEFT JOIN `(select max(review_id) as review_id,entity_pk_value,max(created_at) as created_at from review rev group by entity_pk_value) AS `review_table` 把这两个 `` 去掉!另外请学会如何提问。如果大家只是看你顶楼的代码,是永远找不出问题的!!!问题说明越详细,回答也会越准确!参见如何提问。(提问的智慧