T-SQL WHERE ClauseWhere clause is used to generate the conditions while obtaining data from a table or including it in other tables. If the condition is satisfied, then it returns a particular value from the table. We use WHERE clause to filter the records in database and to fetch the main records. In a SELECT statement, we use the WHERE clause, but it also used in UPDATE, DELETE account, etc. Syntax:We are generating a condition using the logical operators, which are: >, <, =, LIKE, NOT etc. Lets understand it using below example: Example:See the EMPLOYEES table which has the following records -
The following command is an example that would fetch the ID, Name, and Salary fields from the EMPLOYEES table where salary is more significant than 2000. Output of above query:
EXAMPLE: 1The command fetches NAME, AGE, and Salary fields from the EMPLOYEES table. Where the name of employee is 'Chitra.' All strings must be generated inside the single quotes ('') where the numeric values used without any quote: The command generates the given output.
EXAMPLE: 2The command fetches ID, and AGE fields from the EMPLOYEES table. Where the name of employee is 'Chitra.' The command generates the given output.
EXAMPLE 3:The below command is an example, which fetch the ID, Name, and Salary fields from the EMPLOYEES table where AGE is greater than 28. Output:
Next TopicT-SQL LIKE Operator |