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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Count different distincts in one query 1

Status
Not open for further replies.

theScien

Technical User
Aug 27, 2003
98
PT
Hi guys, any way to count different distincts in one query?

Sub-queries not supported in my MySQL v4.0.??

I have this:

Code:
'// Count unique months and years to dimension arrays accordingly
SQL = "SELECT COUNT(DISTINCT Month(Issue)) AS mm FROM tbl_Newsletters WHERE Active = 1;"
Set rsNL = Conn.Execute(SQL)
ReDim arrMonth(rsNL("mm"))

SQL = "SELECT COUNT(DISTINCT Year(Issue)) AS yy FROM tbl_Newsletters WHERE Active = 1;"
Set rsNL = Conn.Execute(SQL)
ReDim arrYear(rsNL("yy"))

As you can see I'm querying twice, works fine, however I would prefer a way to do it in one query.

Anyone?
 
How about:
[tt]
SELECT
COUNT(DISTINCT MONTH(issue)) mm,
COUNT(DISTINCT YEAR(issue)) yy
...
[/tt]
 
Great stuff, never tried this as it didn't appear to be correct syntax somehow.

Thanks for that.
 
That's worth a star, Tony. I didn't know you could do that either.

Andrew
Hampshire, UK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top