Study
Study

Reputation: 1

Mysql Subquery order by date(remove duplicate)

tableName : account

date    name
2016-05 john
2016-05 bob
2016-05 kate
2016-06 jake
2016-06 billy

result is

2016-05  john, bob, kate
2016-06  jake, billy

i am trying this

select date,(select name from account where date ??? )

Upvotes: 0

Views: 107

Answers (3)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 520928

If you want to remove duplicate names which may occur on a given date then you can use GROUP_CONCAT(DISTINCT ...):

SELECT date, GROUP_CONCAT(DISTINCT name)
FROM account
GROUP BY date

Demo here:

SQLFiddle

Upvotes: 0

Mahesh Madushanka
Mahesh Madushanka

Reputation: 2988

Use Group_Concat

select date,group_concat(name) 
 from account  Group by Date

Upvotes: 0

juergen d
juergen d

Reputation: 204746

Group by the date and use group_concat to get a list of names for each date

select date, group_concat(name)
from account
group by date

If needed you can also specify a seperator and even an order like this

group_concat(name separator ', ' order by name)

Upvotes: 1

Related Questions