我有一张如下表:
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
中选择的记录除外。
答案 0 :(得分:0)
您所描述的并不完全是获取不同的记录(因为原始表具有不同的记录),但获取每个Demand_Id
的第一条记录。
SELECT *
FROM Supplies_And_Demands
WHERE ID IN (SELECT MIN(ID)
FROM Supplies_And_Demands
GROUP BY Demand_Id)