Comparison operators test whether two expressions are same or not. These operators can be used on all the sql data types except some of them like text, ntext or image. Equal to, greater then, less than are such operators. The article will let you enable to use these operators with examples.
While arithmetic operators are used to calculate column values, Comparison operators test for similarity between two expressions. You can create conditions in the SELECT statement to retrieve selected rows by using various comparison operators. Comparison operators allow row retrieval from a table based on the condition specified in the WHERE clause. Comparison operators cannot be used on text, ntext, or image data type expressions.
The syntax for using the comparison operator in the SELECT statement is:
SELECT column_list
FROM table_name
WHERE expressiona1 comparison_operator expression2
Where
SELECT BusinessEntityID, NationalIDNumber, JobTitle, VacationHours FROM HumanResources.Employee WHERE VacationHours > 20
In the preceding example, the query retrieves all the rows that satisfy the specified condition by using the comparison operator. The result is shown in the following image:
The SQL Server provides the following comparison operators.
While arithmetic operators are used to calculate column values, Comparison operators test for similarity between two expressions. You can create conditions in the SELECT statement to retrieve selected rows by using various comparison operators. Comparison operators allow row retrieval from a table based on the condition specified in the WHERE clause. Comparison operators cannot be used on text, ntext, or image data type expressions.
The syntax for using the comparison operator in the SELECT statement is:
SELECT column_list
FROM table_name
WHERE expressiona1 comparison_operator expression2
Where
- column_list: list of fields to be shown in output.
- table_name: from the records are to be retrieved.
- expression1 and expression2: any expression on which the operator will be applied.
- comparison_operator: may be one listed below.
SELECT BusinessEntityID, NationalIDNumber, JobTitle, VacationHours FROM HumanResources.Employee WHERE VacationHours > 20
In the preceding example, the query retrieves all the rows that satisfy the specified condition by using the comparison operator. The result is shown in the following image:
The SQL Server provides the following comparison operators.
- = Equal to
- > Greater than
- < Less than
- >= Greater than or equal to
- <= Less than or equal to
- <> Not equal to
- != Not equal to
- !< Not less than
- !> Not greater than
- Records that match one or more conditions
- Records that contain values in a given range
- Records that contain any value from a given set of values
- Records that match a pattern
- Records that contain NULL values
- Records to be displayed in a sequence
- Records from the top of a table
- Records without duplication of values
Tidak ada komentar:
Posting Komentar