简体   繁体   中英

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:

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'." keeps popping up, but disappears when I remove 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

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.)

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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