2012-05-21 93 views
3

我有這對另一個表連接的查詢:如何在不重複數據的情況下進行查詢?

select * from tbl_scales s 
join tbl_recipes r on r.category_id = s.product_id 

,它顯示這樣的冗餘數據,

scale_id r_id  date  recipe_name 

1  1 2012-05-20 Cheese Bread 
6  1 2012-05-21 Cheese Bread 
1  1 2012-05-20 Spanish Bread 
6  1 2012-05-21 Spanish Bread 
3  4 2012-05-20 Pancake 
8  4 2012-05-21 Pancake 
1  1 2012-05-20 Pandesal 
6  1 2012-05-21 Pandesal 

我不知道該怎麼辦this..can別人的幫助我?

+2

什麼是重複,每一行都不一樣。 – xdazz

回答

3

SELECT DISTINCT將消除列中具有相同數據的行。但由於你的日期不同,你可能想使用GROUP BY recipe_name(在查詢結尾添加)。

+0

謝謝岑,小組由我爲我工作.. –

1

distinct關鍵字是你的朋友。

select distinct r_id, scale_id, recipe_name from tbl_scales s 
join tbl_recipes r on r.category_id = s.product_id 
+0

這工作太人了,它確實是特定..謝謝.. –

相關問題