2013-07-26 121 views
0

希望你能理解我的問題。 我想實現這個查詢:如何用mysql選擇一個值組

表:房產

id, name, string_value, property, article_id 
1 test  131  test_name  15 
2 test  131  test_name  17 
3 test  131  test_name  19 
4 test  138  test_name  1 
5 test  138  test_name  119 
6 test  194  test_name  319 
7 test  194  test_name  329 

我想從這個選擇所有string_values(只有一個1的article_id我不關心它可以是RDM)

我需要通過Property.property和Property.string_value和結果來選擇應該是1對這樣的:

結果表:

article_id: 
15 
1 
319 

有沒有辦法通過查詢得到這個?

回答

1

根據您提供的數據,您可以使用此查詢:

SELECT min(article_id) AS `article_id` 
    FROM `table1` 
    GROUP BY `string_value` 
+0

不錯查詢,THX,非常感謝!你做了我的一天:P – Wykk