2014-08-28 32 views
0

當我拉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

+0

你想要哪個的記錄? – Linger 2014-08-28 14:07:40

+0

使用'distinct size' – Sal00m 2014-08-28 14:45:48

回答

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' ; 
+0

您的查詢仍然會在屏幕截圖中拉出所有4條記錄。 – Linger 2014-08-28 14:14:43

+0

它仍然顯示http://screencast.com/t/A5GNVBfImko – 2014-08-28 14:16:53

+0

比你必須使用不同的大小字段 – 2014-08-28 14:18:08

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 
+0

這沒有拉。 – 2014-08-28 14:34:14

+0

...更努力...應該工作。玩列名稱。在sql編輯器中運行;什麼樣的錯誤? – Andrew 2014-08-28 14:35:44