I have a MySQL database with, amongst others, contains a “created_at” column. The column holds the unix timestamp for each entry. On some days, many entries have been made. On others, none. I want to compile a list of dates on which at least one entry was made into the database. I tried the following in phpMyAdmin (on Mysql 5.0) but it gives me an error.
SELECT UNIQUE(DATE_FORMAT(`created_at`, '%d/%m/%Y')) FROM `entries`
To circumvent the error, I removed the UNIQUE part, and tried:
SELECT DATE_FORMAT(`created_at`, '%d/%m/%Y') FROM `entries` WHERE entry_id = 3
This gave me back a NULL value, which is fault because the created_at value for entry_id 3 is 1298050881. Why don’t these two queries work?
Third, eventually, I would like to compile a list of the number of entries made per day, something like:
2011-10-16 1,432
2011-10-17 502
2011-10 18 3,533
For this, I need the first queries to work. So I’m asking for your help. Any help would be greatly appreciated 🙂
Try a group by:
And if you wanted to order the result set just add the following to the end: