2017-08-17 53 views
-3

有什麼辦法找到最小(創建日期)並從訪問查詢中刪除它?vba訪問顯示與最短日期重複的數據

enter image description here

+0

https://www.w3schools.com/sql/sql_delete.asp和https://www.w3schools.com/sql/sql_min_max.asp –

+0

這是一個SQL問題,不VBA。請更正你的標籤 – jsotola

+0

你有什麼嘗試。更多地解釋你正在努力完成的事情。你是否試圖從查詢中刪除結果?或者你是否試圖完全刪除該記錄? –

回答

0

您可以簡單地使用MIN()函數MIN()日期選擇記錄。

SELECT Item_Number, Order_Number, Order_Line_Number, MIN(Creation_Date) 
FROM *tblName* 
GROUP BY Item_Number, Order_Number, Order_Line_Number 

或者您可以在'創建日期'列上使用MAX()函數來排除具有最小日期的記錄。

SELECT Item_Number, Order_Number, Order_Line_Number, MAX(Creation_Date) 
FROM *tblName* 
GROUP BY Item_Number, Order_Number, Order_Line_Number 

或者如果您最初提到的真的想從MIN()日期刪除MS Access表中的記錄然後使用下面的查詢。

DELETE **tbl_A.*** FROM 
*tblName tbl_A* INNER JOIN *tblName tbl_B* 
WHERE 
tbl_A.Item_Number = tbl_B.Item_Number 
AND 
tbl_A.Order_Number = tbl_B.Order_Number 
AND 
tbl_A.Order_Line_Number = tbl_B.Order_Line_Number 
AND 
tbl_A.Creation_Date = tbl_B.MIN(Creation_Date)