简体   繁体   English

列表框中的查询表达式中的MS ACCESS 2010语法错误(缺少运算符)

[英]MS ACCESS 2010 Syntax error (missing operator) in query expression in List Box

I have made a List Box in MS Access 2010. I am using this query for showing up only distinct values from the column (AOM) from which the List Box is getting data: 我在MS Access 2010中创建了一个列表框。我正在使用此查询来仅显示列表框从中获取数据的列(AOM)中的不同值:

SELECT [Exhibit Recording].ReferenceNo, DISTINCT [Exhibit Recording].AOM
FROM [Exhibit Recording];

Now When I am using this an error "syntax error (missing operator) in query expression 'DISTINCT [Exhibit Recording].AOM'." 现在,当我使用此错误时,出现错误“查询表达式'DISTINCT [Exhibit Recording] .AOM'中的语法错误(缺少运算符)”。 keeps popping up, but disappears when I remove DISTINCT. 一直弹出,但是当我删除DISTINCT时消失了。

Is there any way to have distinct values in a list box and not get that error? 有什么办法可以在列表框中具有不同的值而不会出现该错误?

I also tried using: 我也尝试使用:

SELECT DISTINCT [Exhibit Recording].AOM
FROM [Exhibit Recording];

The query runs fine, but the text in the listbox disappears and when you click on it it shows a dark band to show that something has been selected. 该查询运行正常,但是列表框中的文本消失了,当您单击它时,它会显示一个黑带,表明已选择了某些内容。 Any way of getting around this ? 有什么解决办法吗?

As you have discovered, Access SQL does not support queries of the form 您已经发现,Access SQL不支持以下形式的查询

SELECT x, DISTINCT y FROM z

If you haven't done so already, try 如果您还没有这样做,请尝试

SELECT DISTINCT [Exhibit Recording].ReferenceNo, [Exhibit Recording].AOM FROM [Exhibit Recording];

(Notice that DISTINCT immediately follows SELECT. Access SQL supports DISTINCT across the entire query, but not on individual columns.) (请注意,DISTINCT紧跟在SELECT之后。AccessSQL在整个查询中都支持DISTINCT,但不支持单个列。)

If that doesn't give you distinct values for [AOM] and you really need them then you'll have to use a GROUP BY query that arbitrarily chooses a [ReferenceNo] to go along with each [AOM] value: 如果这不能为您提供[AOM]的不同值,而您确实需要它们,则必须使用GROUP BY查询,该查询可以随意选择[ReferenceNo]与每个[AOM]值一起使用:

SELECT First([Exhibit Recording].ReferenceNo), [Exhibit Recording].AOM FROM [Exhibit Recording] GROUP BY [Exhibit Recording].AOM;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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