简体   繁体   English

为什么我无法从此SQL查询中获得任何结果(MS Access)

[英]Why am I not getting any results from this SQL query (MS Access)

I have two tables, one is a local table in Access 2010 ( Employees ) and the other is a linked table in a SQL Server 2014 database ( dbo_Employees ). 我有两个表,一个是Access 2010中的本地表( Employees ),另一个是SQL Server 2014数据库中的链接表( dbo_Employees )。 The query is run inside Access. 该查询在Access内部运行。

For reference, both tables are identical. 供参考,两个表是相同的。 Same columns, same data. 相同的列,相同的数据。 They are literally copies of one another. 它们实际上是彼此的副本。 The only difference is that I deleted one record from the SQL Server table. 唯一的区别是我从SQL Server表中删除了一条记录。 I did this because the query I'm trying to run is to find all the records in the Employees table that match records that exist in the dbo_Employees table. 我这样做是因为我要运行的查询是在Employees表中查找与dbo_Employees表中存在的记录匹配的所有记录。 This should return all but the one deleted record. 这将返回除一个已删除记录以外的所有记录。 While it does exist in the Employees table, since it doesn't exist in the dbo_Employees table, it would be excluded in the results. 尽管它确实存在于Employees表中,但由于它不存在于dbo_Employees表中,因此将其排除在结果之外。 Here is the query: 这是查询:

select Employees.ID
from Employees
where Employees.ID IN (SELECT dbo_Employees.ID FROM dbo_Employees)

When I run this, I get nothing. 当我运行它时,我什么也没得到。 What am I doing wrong? 我究竟做错了什么?

Are you sure you have matching data in both tables? 您确定两个表中都有匹配的数据吗?

What does 是什么

SELECT
    Employees.ID
    , dbo_Employees.ID
FROM Employees 
    INNER JOIN dbo_Employees ON Employees.ID = dbo_Employees.ID 

return? 返回? Does it return any rows? 它返回任何行吗?

Otherwise, what does the following query return? 否则,以下查询返回什么?

SELECT 
    Employees.ID
    , dbo_Employees.ID
FROM Employees 
    FULL JOIN dbo_Employees ON Employees.ID = dbo_Employees.ID

You can use this second query to see what data matches in both of your tables. 您可以使用第二个查询来查看两个表中匹配的数据。 The query will output the data in both tables while putting the matching ID values on the same row and displaying a NULL value in one or the other table's corresponding ID column if there is no match. 查询将在两个表中输出数据,同时将匹配的ID值放在同一行上,如果不匹配,则在一个或另一个表的对应ID列中显示NULL值。

(I know this is not a legitimate answer, it's more of a comment, but it's the first things OP should check) (我知道这不是一个合理的答案,更多是评论,但这是OP应该检查的第一件事)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM