heavykenny
heavykenny

Reputation: 33

How to combine all dates for every userId?

I have a MySQL table with userId, movieId and date. I'm having issues with my query. I would like to query and list out different date tagged with a movieId under each userId.

userId movieId  date
  1     A     1:00PM
  1     A     3:00PM
  2     A     2:00PM
  2     C     8:00PM
  2     C     9:00PM

I want something like this

UserId --Movie(Time)
  1    A     1:00PM, 3:00PM
  2    A     2:00PM
  2    C     8:00PM,9:00PM

Upvotes: 0

Views: 66

Answers (1)

Zaynul Abadin Tuhin
Zaynul Abadin Tuhin

Reputation: 31993

use group_concat function

select UserId ,movieId, group_concat(date separator ',') 
from your_table group by UserId ,movieId 

Upvotes: 3

Related Questions