Free Information Technology Magazines and eBooks

Thursday, February 05, 2009

SQL: SELECT DISTINCT COUNT IN MS Access Database

One of Microsoft Access limitation is it doesn't support a very useful query SELECT COUNT with DISTINCT column like this one:

SELECT COUNT(DISTINCT columnname) FROM tablename


However the is a workaround. You can use the ability of the FROM statement to retrive from a SELECT query statement as shown below:

SELECT Count(Colname) FROM (SELECT DISTINCT Colname FROM myTable)
SELECT Count(Colname) FROM (SELECT DISTINCT Colname FROM myTable WHERE colfind=findvalue)


Now you have it. A SELECT DISTINCT COUNT for Microsoft Access. Until next time!

0 comments: