October 23, 2011

Use of WITH keyword in SQL Server

We can use WITH keyword to make our query more simplified.

Let’s take a simple example:
We have some data in our table as below

image

Now output should come in this way:

image

Means first entry from each group.
My whole T-SQL will look like this.This is the very generous use of WITH keyword.

image

That’s It.
Enjoy Learning.

No comments:

Post a Comment