When reading data from the database with Between Operator, we can specify a range for the data we filter in WHERE Clause. Let’s make an example for a better understanding of the subject.
First, let’s create a table as below and add a few records.
CREATE TABLE [dbo].[MyTable](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Name] [varchar](50) NOT NULL,
[Age] int NOT NULL
) ON [PRIMARY]
INSERT INTO [dbo].[MyTable] VALUES ('Nurullah',34),('Faruk',27),('Hakan',36),('Ogun',27)
List the people aged 30 to 40 years old:
SELECT * From [dbo].[MyTable] WHERE Age Between 30 AND 40
List the people whose names are between N and P:
SELECT * From [dbo].[MyTable] WHERE Name Between 'N' AND 'P'
List the people whose names are not between N and P:
SELECT * From [dbo].[MyTable] WHERE Name NOT Between 'N' AND 'P'