我有三张桌子:
字段
ID | FarmID | FIELD_NUM | Year
农场
ID | ClientID
客户
ID | CLIENT_NUM
我有一个简单的查询来从Clients表中获取CLIENT_NUM:
SELECT
(SELECT CLIENT_NUM FROM Clients
WHERE ID = (SELECT ClientID FROM Farms WHERE ID = FarmID)) AS CID
FROM Fields
WHERE Year = 2014 AND FIELD_NUM = '28-2'
在SQL Server中,这很好用;但是,在Microsoft Access中它需要永远。有没有更好的方法来运行此查询?
答案 0 :(得分:2)
请尝试使用JOIN
,而不是使用子查询。根据Access如何优化查询,它可以帮助提高性能,但它也有助于提高可读性:
SELECT Clients.CLIENT_NUM as CID
FROM (Clients INNER JOIN Farms ON Clients.ID = Farms.ClientID)
INNER JOIN Fields ON Farms.ID = Fields.FarmID
WHERE Fields.Year = 2014 AND Fields.FIELD_NUM = '28-2'