-1

I have 2 tables:

1. Post table (:id, :content)
2. Comment table (:id, :post_id, :content)

I'm using this code:

@result = Comment.where("content LIKE :query", query: "%#{@keyword}%")

@result has more dupplicated posts, how can I select unique collection by DISTINCT :post_id Thanks for your help!

Thi Tran
  • 681
  • 5
  • 11

1 Answers1

1

just for the record another solution

@result = Comment.where("content LIKE :query", query: "%#{@keyword}%").group(:post_id)
Tim Kretschmer
  • 2,272
  • 1
  • 22
  • 35