How to Return Subset of Rows in SQL

In this article I am going to explain how to return a subset of selected rows in SQL.
  • 4839

Introduction

In this article I am going to explain about how to return a subset of selected rows in SQL. When you use select statement it shows all data in result set. There are many situation when you need only a subset of selected rows. To fetch a subset of selected rows we use TOP clause fallowed by integer value. We can also use PERCENT clause to fetch n percent rows in result set. Notice that statement must have ORDER BY clause.

A Statement that create mcnemp table

mcnemp (1).jpg

Statements that insert data in mcnemp table

mcnemp (2).jpg

A Statement that is used to fetch data from mcnemp table

mcnemp.jpg

A SELECT Statement with a TOP clause

Clipboard26.jpg

A SELECT Statement with TOP clause and PERCENT keyword

Clipboard28.jpg


© 2020 DotNetHeaven. All rights reserved.