Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to write an SQL statement for counting distinct 1

Status
Not open for further replies.

trideryck

MIS
Jun 20, 2005
10
US
I am using VFP 6.0 and I am trying to put together a simple SQL statement that will count how many occurences of each distinct record I have in my database. Here is a sample of my data:

First Last City State Zip
John Adams Midland Texas 79703
John Adams Midland Texas 79707
John Smith Midland Texas 79703
John Smith Midland Texas 79703
John Smith Midland Texas 79703
John Smith Angelo Texas 76901
Sally Barnes Odessa Texas 79769
Sally Barnes Odessa Texas 79769

I want to select distinct for First+Last+City+State+Zip and then count how many records in my database have that distinct entry. So I want my output to look something like this:

First Last City State Zip Count
John Adams Midland Texas 79703 1
John Adams Midland Texas 79707 1
John Smith Midland Texas 79703 3
John Smith Angelo Texas 76901 1
Sally Barnes Odessa Texas 79769 2

Any help would be appreciated, thanks!

 
Code:
SELECT first, last, city, state, zip, count(*) ;
   FROM yourTable ;
   GROUP BY first, last, city, state, zip
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top