RE: SQL Finding the most frequent occurance of a value (mode)
843854Apr 30 2005 — edited Jun 1 2006Hi,
I have a column in a table which contains values, I would like to find out which value occurs the most often. I thought I had seen a similar post in this forum, but can not find it anywhere. I have looked on the internet and have found this query, but it does not work for me.
Query: "SELECT TOP 1 myColumn FROM (SELECT myColumn COUNT(*) cnt FROM myTable GROUP BY myColumn) DERIVEDTBL ORDER BY cnt DESC"
I have spent ages trying to get this to work, with no luck.
I get this exception "java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error (m
issing operator) in query expression 'COUNT(*) cnt'."
Any help would be greatley appreciated, whether it's an answer or a reference to a source that is more appropriate. Any links to decent SQL forums would be good, I have had trouble finding any.
Thanks