alez
alez

Reputation: 136

Display records per day

I have a table like this:

id | date | name 

And the desired output is displaying the record per day of the month:

Day 1 - name1 , name2, name3
Day 2 - name4
Day 3 - name5, name6
.
.
.

I know how to do this with php but I wonder If it is possible to do it with a mySQL sentence ..

Anyone can help?

Upvotes: 1

Views: 212

Answers (3)

Aziz Shaikh
Aziz Shaikh

Reputation: 16524

Try this:

SELECT DAYOFMONTH(date) AS Day, GROUP_CONCAT(name SEPARATOR ', ') AS Name
FROM table1
GROUP BY Day

Working demo: http://sqlfiddle.com/#!2/ecc33/1

Upvotes: 5

Filipe Silva
Filipe Silva

Reputation: 21657

Using GROUP_CONCAT() alows you to do that:

SELECT date,group_concat(name)
FROM tableName
GROUP BY date

The group in this query will be done by date, not the day of the month. If you have one record in 2013-01-01 it will not be in the same group as 2013-02-01. If that is what you are looking for, @Aziz's answer is what you are looking for.

Upvotes: 0

Pramod
Pramod

Reputation: 1041

Select date,group_concat(name) from table1 group by date 

Try this.

Upvotes: 0

Related Questions