Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I used distinct to remove duplicates in this query?

I have the following table: Table

I am trying to write a query (that I will include in another query) to display how many account numbers there are per symbol.

I wrote the following query:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

SELECT Symbol,
(SELECT DISTINCT COUNT([Account Number]) FROM [Open] T2 WHERE T2.Symbol = T1.Symbol) AS Accounts
FROM Open T1
GROUP BY [Symbol];

The query displays like this but it counts the same account number multiple times per symbol. EURUSD should have 3 and USDJPY should only have 1 next to it.

It should display like this.

I am trying to include this as part of another big table that has other information next to each symbol too.

I will appreciate any assistance.

>Solution :

Access doesn’t support count(DISTINCT ...). You can try

SELECT Symbol, count(*) AS Accounts
  FROM (SELECT DISTINCT Symbol, Account FROM Open) 
 GROUP BY Symbol;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading