Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

In SQL Server a HAVING without GROUP BY is a way to filter out duplicates.


It seems to error out.

  select name, count(*)
  from queries
  having count(*) > 1
Column 'queries.name' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.


Like this. There is more than one way to do it:

  -- List employees who have the biggest salary
  -- in their departments
  select
      Name
  from
      Employees e1
  where
      exists
      (
          select
              1
          from
              Employees e2
          where
              e2.DepartmentID = e1.DepartmentID
          having
              max(e2.Salary) = e1.Salary
      )




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: