title: Rails/SQL - How to filter by distinct value in a group
body: <p>I'm working in Rails, but an answer in SQL is equally helpful. Let's say I have a table of Users and a table of Purchases. I want to find the Users who have only ever bought Item A. I was hoping to use a query along the lines of:</p>
  <p><code>User.joins(:purchases).group(:id).having(&quot;DISTINCT(item) = 'A'&quot;).pluck(:id)</code></p>
  <p>This is a simplification of the question I need to answer, but this grouping issue is my main roadblock. For that reason, I'm hoping for an answer that is logically very similar, as other workarounds would likely not apply.</p>