SELECT查询从一个表中返回一行,所有值都设置为Null [英] SELECT query to return a row from a table with all values set to Null
问题描述
我需要进行查询,但是每个字段的值都为空。 Gordon Linoff给了我这个需求的线索:
SQL空查询结果
,它是:
I need to make a query but get the value in every field empty. Gordon Linoff give me the clue to this need here: SQL Empty query results which is:
select t.*
from (select 1 as val
) v left outer join
table t
on 1 = 0;
这个查询在PostgreSQL上完美的发现,但是试图在Microsoft Access中执行它时会出错,它说1 = 0表达式不被承认。
This query wors perfectly on PostgreSQL but gets an error when trying to execute it in Microsoft Access, it says that 1 = 0 expression is not admitted. How could it be fixed to work on microsoft access?
请问,
推荐答案
如果表的数值主键列的值为非负数,那么以下查询将在Access中运行。主键字段为[ID]。
If the table has a numeric primary key column whose values are non-negative then the following query will work in Access. The primary key field is [ID].
SELECT t2.*
FROM
myTable AS t2
RIGHT JOIN
(
SELECT TOP 1 (ID * -1) AS badID
FROM myTable AS t1
) AS rowStubs
ON t2.ID = rowStubs.badID
这是使用Access 2010进行测试。
This was tested with Access 2010.
这篇关于SELECT查询从一个表中返回一行,所有值都设置为Null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!