简体   繁体   中英

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 ). The query is run inside 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. 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. 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. 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.

(I know this is not a legitimate answer, it's more of a comment, but it's the first things OP should check)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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