Search code examples
sqlsql-serversyntax-errorhaving

Facing issue in having clause


select *
from db_user
order by date_created asc OFFSET 1 ROWS FETCH NEXT 10 ROWS ONLY
having full_name like 'Admin%';

Getting Error:

[S0001][156] Incorrect syntax near the keyword 'having'.

How to resolve this issue because 'where' clause also giving error.


Solution

  • having is used to filter out grouped results from a group by clause. If you just want to filter out rows, you should use a where clause. Note that it should come before the order by clause:

    SELECT   *
    FROM     db_user
    WHERE    full_name LIKE'Admin%' -- Here!
    ORDER BY date_created ASC OFFSET 1 ROWS FETCH NEXT 10 ROWS ONLY