当我自己运行SQL脚本时,参考下面的代码,它正确返回2条记录,ID 1和3,因为Orders表中没有ItemID 2的需求。当我使用SQL获取一个记录集我发现我有3条记录返回; ID 1,2和3.我只期待ID 1和3。
我做错了什么?
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("Item")
'SQL:
'SELECT Item.ID
'FROM Item
'WHERE Item.QOH > 0 AND Item.ID IN (SELECT ItemID FROM Orders WHERE Orders.Demand > 0);
Do Until rs.EOF
Debug.Print rs.Fields("ID")
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Set db = Nothing