|
In SQL there are many clauses which are widely used in SQL database. In SQL
server mainly two clauses are widely used namely: WHERE and TOP. Let’s see these
two descriptions briefly.
SQL WHERE Clause:
The WHERE clause is used to extract only those records that fulfill specified
criterion. The WHERE clause allows you to filter the results from an SQL
statement - Select, Update, or Delete statement.
Example: Using WHERE clause
--- select data
field from STUDENT_DETAIL table where
condition are true
select
* from
STUDENT_DETAIL where id
= 102
Desired Output:
102
VARUN SINGH
SQL TOP Clause:
The TOP clause is used to specify the number of records to return. The TOP
clause can be very useful on large tables with thousands of records. Returning a
large number of records can impact on performance.
The "TOP" clause will now allow us to do Data Manipulation and also allow
similar criteria results to be displayed by using the TIES option.
Example: Using TOP Clause
--- select top
3 data field from STUDENT_DETAIL
select top(3)*
from STUDENT_DETAIL
//with condition
--- select top
3 data field from STUDENT_DETAIL
select top(3)*
from STUDENT_DETAIL
where id = 102
--- update top
3 data field from STUDENT_DETAIL where condition is true
update
top(3) STUDENT_DETAIL set
name = 'kajal'
where id = 102
|