[英]MS Access Query to get Distinct records from a table
我有一個如下表:
ID Demand_ID Supply_ID Supply_Skill Supply_Designation Supply_Location
1 D10 S10 Python engineer Mumbai
2 D10 S16 Python engineer Mumbai
3 D10 S2 Python engineer Mumbai
4 D10 S7 Python engineer Mumbai
5 D12 S12 Java Manager Bangalore
6 D1 S1 Java Senior engineer Bangalore
7 D1 S11 Java Senior engineer Bangalore
8 D1 S3 Java Senior engineer Bangalore
9 D2 S10 Python engineer Mumbai
10 D2 S16 Python engineer Mumbai
11 D2 S2 Python engineer Mumbai
12 D2 S7 Python engineer Mumbai
13 D3 S1 Java Senior engineer Bangalore
14 D3 S11 Java Senior engineer Bangalore
15 D3 S3 Java Senior engineer Bangalore
如何獲得唯一的記錄,如下所示:
ID Demand_ID Supply_ID Supply_Skill Supply_Designation Supply_Location
1 D10 S10 Python engineer Mumbai
5 D12 S12 Java Manager Bangalore
6 D1 S1 Java Senior engineer Bangalore
10 D2 S16 Python engineer Mumbai
14 D3 S11 Java Senior engineer Bangalore
請告訴我一個邏輯來獲得獨特的記錄,像上面,並用以下條件就像從數據Supply_ID
到Supply_Location
不應該被重復的Demand_ID
。
像上面的示例一樣, Demand_Id
D10
和D2
具有相同的下一列記錄集。 如果該列之一與D10
匹配,則不應為D2
重復。 對於D2
它可以從相應列中選取任何記錄,但已從D10
選取的記錄除外。
您描述的並不是完全獲得不同的記錄(因為原始表具有不同的記錄),而是獲得每個Demand_Id
的第一條記錄。
SELECT *
FROM Supplies_And_Demands
WHERE ID IN (SELECT MIN(ID)
FROM Supplies_And_Demands
GROUP BY Demand_Id)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.