Before writing query using CTE first we learn what is CTE
Common Table Expression are temporary result sets which is defined within the execution scope of a single select , insert ,update, delete or createview statement.
Advantage of CTE
- Can be used to create a recursive query.
- Can be substituted for a view.
- Can reference itself multiple times..
- Improve readability.
- Easy maintenance of complex query.
Query for removing record
- with delrecord as (
- Select * , Row_Number() over(partition by EmpId, EmpName, Salary order by Name desc) as mydel From Emplyee)
-
- Delete from delrecord where mydel > 1