我需要选择每个产品的第一个拇指图像(这里是它的实体ID)
我的查询
SELECT entity_id as product_id, value FROM catalog_product_entity_media_gallery
但是它返回我需要查询的所有图像从每个id中选择第一张图像可以提供任何帮助。
答案 0 :(得分:1)
您可以将从0索引限制的返回行限制为1个记录。
SELECT entity_id as product_id,value FROM catalog_product_entity_media_gallery GROUP BY entity_id
答案 1 :(得分:1)
SELECT entity_id as product_id, value FROM catalog_product_entity_media_gallery GROUP BY entity_id
答案 2 :(得分:1)
试试这个,使用GROUP BY进行分组并命令它们获取第一个
SELECT entity_id as product_id, value FROM catalog_product_entity_media_gallery GROUP BY entity_id ORDER BY entity_id
答案 3 :(得分:1)
你使用GROUP BY条款
SELECT entity_id as product_id, value FROM catalog_product_entity_media_gallery
GROUP BY entity_id ORDER BY entity_id
ORDER BY
entity_id获取第一个拇指图像
答案 4 :(得分:1)
这是查询
SELECT entity_id as product_id, value FROM catalog_product_entity_media_gallery GROUP BY product_id ORDER BY `value_id` ASC
当您执行
分组GROUP BY
时,您正在对所有相似内容进行分组 product_id或entity_id为one&因为你ORDER BY
value_id by 升序第一个插入的行将位于顶部并按
检查这两个链接以获取更多详细信息http://www.w3schools.com/sql/sql_groupby.asp& http://www.w3schools.com/sql/sql_orderby.asp