I have tried this query to get the duplicate records.but I am getting this error.
select * from Codes
where id = 35712 and isactive = 1
group by line_num
having count(*) > 1
I am getting this error.
Msg 8120, Level 16, State 1, Line 1
Column 'Codes.code_id' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
here code_id is the primary key for this table.
can anybody help me out how to get the code_id which have duplicates in this table.
Thanks
In SQL Server 2005 and later you can use aggregate window functions:
References:
Aggregate Functions (Transact-SQL)
OVER Clause (Transact-SQL)
WITH common_table_expression (Transact-SQL)