Syntax error (missing operator) in query expression ....
843854Apr 3 2003 — edited Apr 3 2003Hi everyone,
I have a simple table called User_Times made of 3 columns: ID,Email, and Time_ID. I need to execute few sql statements that would retrieve some records from this table. However, as soon as my program executes the first one:
String distinctRecipients="SELECT COUNT(DISTINCT Email) FROM User_Times";
rs1=stmt1.executeQuery(distinctRecipients);
I get the following error:
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'COUNT(DISTINCT Email)'.
What I'm trying to do is to get the number of distinct emails (since the column can have several same email entries) and this sql statement is what I found on several sql tutorials on the web but obviously it doesn't work here. Can someone say why and how to fix ? Also, from the same tutorials I created two more sql's (though I haven't ran them yet because of the exception from the first one) that probably won't work as well if this one doesn't work. The one is supposed to return all the distinct emails and I did it like following:
String sql_emails="Select Distinct Email from User_Times";
and the other one needs to find the Time_ID that occurs the most (the Time_ID can consist for example the following values: 1,2,3,3,3,3,4,5 so I would need sql that will return 3 since it occurs 4 times and other values occur only once each). I would really appreciate if someone can help me with this problem. Thanks in advance, Jimmy.