问题
I've been successfully using
SELECT [field] FROM [Table] IN 'Network Location';
this question filled me in on that Access SQL Query from another DB
My question is: How does a JOIN fit into this framework
Is it
SELECT [field]
FROM [Table] IN 'Network Location'
JOIN [Table2]
ON [Table2].field = [Table].field;
or
SELECT [field]
FROM [Table]
JOIN [Table2]
ON [Table2].field = [Table].field IN 'Network Location' ;
it feels like the former is the correct one. SQL statements are supposed to be like sentences and that one feels most appropriately ordered.
回答1:
Consider the bracketed or backticked name qualifier to query from external Access databases. Semantically, this would follow other RBDMS' (e.g., Oracle, Postgres, SQL Server, MySQL, SQLite) period qualifiers to query across clusters, schemas, databases on same machine/server. From there use table aliases for referencing in SELECT
, JOIN
, WHERE
, and other clauses.
SELECT t1.[field]
FROM [C:\Path\To\External\myDatabase.accdb].[Table] t1
INNER JOIN [Table2] t2
ON t2.field = t1.field;
SELECT t1.`field`
FROM `C:\Path\To\External\myDatabase.accdb`.`Table` t1
INNER JOIN `Table2` t2
ON t2.field = t1.field;
Do note, Access requires JOIN
to be specific: INNER
, LEFT
, RIGHT
.
And thanks to the JET/ACE SQL engine, you can even query Excel workbooks and CSV files in similar manner assuming data is contiguous in a table-like range:
SELECT *
FROM [Excel 12.0 Xml;HDR=Yes;Database=C:\Path\To\myWorkbook.xlsx].[SheetName$] AS t;
SELECT t.*
FROM [text;database=C:\Path\To\Folder].myFile.csv AS t;
来源:https://stackoverflow.com/questions/57167374/access-sql-from-in-and-joins