1

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 ?

4

1 回答 1

0

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;
于 2013-10-31T06:48:49.470 回答