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

Count records with each unique value in one field 1

Status
Not open for further replies.

PeDa

Technical User
Oct 10, 2002
227
NL
My MySQL table contains a field Date and a field Information; there are about 5000 records, and the value of Date can be one of about 20 values. I want to generate a query that will return the various dates and the number of records with that value of Date:
Code:
Date         No of records with this date
<date1>  <for example: 123>
<date2>  <for example: 76>
<date3>  <for example: 86>
[code]

The intention is to populate the dropdown list "Kies een datum..." on the top right of [url=http://www.pdavis.nl/ShowSet.php?]this page[/url], which - at the moment - is populated from a separate manually filled table with the various dates and the number of records (photos) for each date - not very elegant.
 
Something like this perhaps?

Code:
SELECT DateColumnName as ThisDate, COUNT(DateColumnName) group by DateColumnDate



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Unfortunately this yields just one record with the Date from the first record in the table and the total number of records in the table:
Code:
SELECT fDatum AS ThisDate, COUNT(fDatum) FROM tbFotos
 
Use the Group clause.

Code:
SELECT fDatum AS ThisDate, COUNT(fDatum) FROM tbFotos [b]GROUP BY fDatum[/b]

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top