I have a membership list database table (.MDB MS-Access, accessed via <CFQUERY>) with four email address fields (email1, email 2, email3, email4) - all in same table. (Some folks have multiple email addresses, often from different Email Service Providers - ESPs.)
I need to develop an SQL query (or series of queries) to produce a list of all the ESPs (e.g. gmail.com, comcast.net, etc.) along with a count of how many of each there are, across all four of these fields. As an example, the desired end result output should be a single list that looks something like:
comcast.net (6)
gmail.com (14)
cs.com (1)
hotmail.com (4)
att.net (12)
aol.com (2)
. . . .
etc.
So far, I have successfully used the following to get a list of all ESPs from one of the four fields:
<!--- get list of ESPs (e.g. @comcast.net) --->
<cfquery name="cfqGetESP" datasource="#email_datasource#">
SELECT MID(email1, INSTR(email1, '@') + 1)
AS esp
FROM tblMembers
WHERE email1 IS NOT NULL
</cfquery>
QUESTION 1: What would be the syntax to have this query get those results across all four fields? (email1, email2, email3, email4)
I then tried the following to generate a list with a count of each distinct ESP:
<!--- count how many total occurrences of EACH individual ESP were found --->
<cfquery name="cfqCountESP" dbtype="query">
SELECT esp, COUNT(esp) AS instances
FROM cfqGetESP
GROUP BY esp
ORDER BY esp ASC
</cfquery>
<p>TEST DISPLAY<br>
<cfoutput>
<cfloop query="cfqCountESP">
#cfqCountESP.esp#<br>
</cfloop>
</cfoutput>
But, my output results in just a list of distinct ESPs without the count of each:
aol.com
att.net
comcast.net
cs.com
gmail.com
hotmail.com
. . . .
etc.
QUESTION 2: What would be the correct way (added variable?) to display output with the count of each, such as "comcast.net (6)"?
#cfqCountESP.esp# (#cfqCountESP.??????#)
Thanks for your help!