MySQL:重复条目拉动

时间:2014-08-28 14:05:55

标签: php mysql

当我拉下MySQL代码时:

SELECT distinct *
FROM product_size AS ps 
INNER JOIN product_type AS pt ON ps.product_id = pt.product_id
WHERE product_type = 'Business Card' 
;

提取以下图片:

enter image description here

我要做的是确保当我们从我们的网站上提取它时,它只在我们的页面上拉出一个大小的实例。

所以基本上,当我们在我们的网站上进行选择时,我希望它能够拉大小。

当我在我们的网站上提取它时,会出现以下内容:

http://screencast.com/t/eowXtDol6IOZ

2 个答案:

答案 0 :(得分:1)

我假设您的product_id是唯一的,因此请使用product_id而不是所有记录。

SELECT distinct ps.product_id, ps.*
FROM product_size AS ps 
INNER JOIN product_type AS pt ON ps.product_id = pt.product_id
WHERE product_type = 'Business Card' ;

答案 1 :(得分:0)

你可以像这样轻松删除不必要的物品

SELECT DISTINCT size, produce_type, p_dimension
FROM 
(SELECT distinct *
FROM product_size AS ps 
INNER JOIN product_type AS pt ON ps.product_id = pt.product_id
WHERE product_type = 'Business Card')

SELECT DISTINCT rs.size, rs.produce_type, rs.p_dimension
FROM 
(SELECT distinct *
FROM product_size AS ps 
INNER JOIN product_type AS pt ON ps.product_id = pt.product_id
WHERE product_type = 'Business Card') rs