INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Count records with each unique value in one field

Count records with each unique value in one field

Count records with each unique value in one field

(OP)
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 this page, 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.

RE: Count records with each unique value in one field

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

RE: Count records with each unique value in one field

(OP)
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 

RE: Count records with each unique value in one field

Use the Group clause.

CODE

SELECT fDatum AS ThisDate, COUNT(fDatum) FROM tbFotos GROUP BY fDatum 

----------------------------------
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

RE: Count records with each unique value in one field

(OP)
Yes indeed; thank you!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close