Search code examples
ms-accessms-access-2007

Access query runs on table that does not exist in database


I would like to recreate a few existing Access queries in a new database so that I can tweak them a bit. The problem I am running into is that some of the tables being queried do not seem to exist in the current database. These tables all end with a 1.

For example, INV_MTL_ITEM_LOCATIONS is an imported table in the database, but INV_MTL_ITEM_LOCATIONS_1 is being queried even though it does not show up in the tables panel on the left.

Is this some type of duplication functionality that I am not aware of? The query runs without any errors.


Solution

  • No, the query runs on an aliased table. It's actually just querying INV_MTL_ITEM_LOCATIONS

    Using SQL, you can create an alias for a table. This is especially useful when querying the same table twice in one query, but also commonly used to shorten queries.

    Your query will probably look something like this:

    SELECT something
    FROM INV_MTL_ITEM_LOCATIONS AS INV_MTL_ITEM_LOCATIONS_1
    

    Access automatically creates these aliases when using the query builder and if you add the same table more than once. When removing the non-aliased table, the other one stays aliased.

    This is entirely normal, and as far as I know, never a problem.