SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Count Unique Rows
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

helpwithSQL1502
Starting Member

1 Posts

Posted - 07/24/2013 :  23:26:37  Show Profile  Reply with Quote
Hi everyone. I have a table in Access 2007 that has about 30 field names and I want to have a count of how many unique rows there are in each field. I want to have these results put into another table that will just have the field name and then the count of how many unique rows there are.

I have code in VBA that will loop through my SQL and change out the field name, but I can't seem to get the SQL right before I can start looping it. For just one field name this would be what I have to count the unique names...

So far I have this:

INSERT INTO newtable
COUNT(*) FROM (SELECT Raw_Table.FieldName, COUNT(Raw_Table.FieldName) AS CountOfFieldName
FROM Raw_Table
GROUP BY Raw_Table.FieldName);

And its not going too well.
If any of you SQL gurus could fix this problem for a novice like myself, it would really be a big help. Thanks in advance.

bandi
Flowing Fount of Yak Knowledge

India
2210 Posts

Posted - 07/25/2013 :  00:31:19  Show Profile  Reply with Quote
-- You mean to have number of different values in the column. Then Query should be as follws:
SELECT COUNT(DISTINCT Raw_Table.FieldName)
FROM Raw_Table


--
Chandu
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000