Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • 2
    Hey, I know this answer is 7 years old, but if you're still around would you mind explaining how it works? Solved my problem as well! Commented Dec 6, 2019 at 18:04
  • 8
    Using a HAVING here instead of a second SELECT...WHERE causes this to be a single query, instead of the second option which executes that second SELECT...WHERE call many times. See more here: stackoverflow.com/q/9253244/550975 Commented Dec 6, 2019 at 18:38
  • I get the infamous [EmailAddress] must appear in the GROUP BY clause or be used in an aggregate function error. Is the only fix - editing the sql_mode? Commented Jul 16, 2020 at 16:21
  • Well, in the query above, [EmailAddress] IS in the GROUP BY Commented Feb 2, 2023 at 21:25