Wednesday, 14 February 2018

How to use SQL BETWEEN Operator

BETWEEN operator is use from filter data range wise

BETWEEN Syntax

SELECT YourColumnName FROM YourTableName WHERE ConditionColumnName BETWEEN Value1 AND / OR Value 2

BETWEEN Example

1. SELECT * FROM Employee WHERE Salary BETWEEN 5000 AND 10000

2. SELECT * FROM Student WHERE RegisterDate BETWEEN 2018-01-08 AND 2018-01-10

How to use SQL IN Operator in Query

IN operator use for get single condition or multiple condition data from sql table

IN Operator syntax

SELECT YourColumnName FROM YourTableName WHERE ConditionColumnName IN (Values)

IN Operator Example

IN Operator you can use like

SELECT * FROM City WHERE CityName IN ('T1', 'T1')

OR

SELECT * FROM City WHERE CountryName IN (SELECT CountryName FROM Country WHERE CountryName LIKE 'a%')

How to use SQL LIKE operator different way in SQL Query

LIKE operator use in WHERE condition that search pattern wise in column

LIKE operator use 2 wildcard

1. % percent sign use for more than 1 characters

2. _ underscore use for single characters

LIKE Syntax

SELECT ColumnName FROM YourTableName WHERE ColumnName LIKE YourCondition

Example

1. SELECT TOP 1 * FROM Client WHERE LastName LIKE 'A%'
- filter records start with A character

2. SELECT TOP 1 * FROM Client WHERE LastName LIKE '%A'
- filter records end with A character

3. SELECT TOP 1 * FROM Client WHERE LastName LIKE '%A%'
- filter records anywhere get char A in field

4. SELECT TOP 1 * FROM Client WHERE LastName LIKE '_A%'
- filter records that contains second char A

5. SELECT TOP 1 * FROM Client WHERE LastName LIKE 'A%S'
- filter records that first char A and last char is S