0

I have 3 tables on my database with the following data:

tb_collection: id_collection, name

tb_collection_product: id, id_collection, id_product

tb_product: id_product, photo

Here's what I'm trying to do:

Select the last 2 products of each collection...I've tried group by with no luck.

4

2 回答 2

0

刚刚开始执行以下操作:

添加了一个名为“show”的新列作为 tinyint 字段,默认为 0 和 1 为选中状态。然后,下面的mysql:

选择 tb_product.photo, tb_collection_product.* 从 tb_product,tb_collection_product WHERE tb_collection_product.show=1 AND tb_collection_product.id_product = tb_product.id_product

于 2012-09-05T13:17:49.873 回答
0

试试这个查询

SELECT   tb_collection.id_collection,tb_collection.name , 
         tb_collection_product.id , tb_collection_product.id_collection, 
         tb_collection_product.id_product, tb_product.id_product, 
         tb_product.photo 
FROM     tb_collection 
             INNER JOIN tb_collection_product 
                    ON tb_collection.id_collection=tb_collection_product.id_collection 
             INNER JOIN tb_product 
                    ON tb_collection_product.id = tb_product.id_product 
ORDER BY tb_collection.id_collection DESC limit 2
于 2012-09-05T02:50:11.007 回答