Tuesday, 13 February 2018

SQL SELECT TOP Record Condition

SQL TOP Condition is use for return number of record return from table

SQL TOP is useful if large number of records store in your table. TOP condition is useful in performance

SELECT TOP Syntax

SELECT TOP No or Percent ColumnName FROM YourTableName WHERE Condition

Example

1. SELECT TOP 10 * FROM City
- Return 10 records from city table

2. SELECT TOP 10 PERCENT * FROM City
- Return TOP 10 percent record from city table

How to use MIN() and MAX() function in SQL Query

- MIN() function return small value of column

- MAX() function return large value of column

MIN() Syntax

SELECT MIN(YourColumnName) FROM YourTableName WHERE Condition

MAX() Syntax

SELECT MAX(YourColumnName) FROM YourTableName WHERE Condition

Example

1. SELECT MIN(Salary) AS LowSalary FROM Employee

2. SELECT MAX(Salary) AS HighSalary FROM Employee