This works as expected:
SELECT "Mike" AS FName
This fails with the error “Query input must contain at least one table or query”:
SELECT "Mike" AS FName
UNION ALL
SELECT "John" AS FName
Is this just a quirk/limitation of the Jet/ACE database engine or am I missing something?
You didn’t overlook anything. Access’ database engine will allow a single row
SELECTwithout aFROMdata source. But if you want toUNIONorUNION ALLmultiple rows, you must include aFROM… even if you’re not referencing any field from that data source.I created a table with one row and added a check constraint to guarantee it will always have one and only one row.
That
Dualtable is useful for queries such as this:Another approach I’ve seen is to use a
SELECTstatement withTOP 1or aWHEREclause which restricts the result set to a single row.Note check constraints were added with Jet 4 and are only available for statements executed from ADO.
CurrentProject.Connection.Execute strSqlworks becauseCurrentProject.Connectionis an ADO object. If you try to execute the same statement with DAO (ieCurrentDb.Executeor from the Access query designer), you will get a syntax error because DAO can’t create check constraints.