Master SQL Server From Scratch

Clear, interactive, and structured SQL Server lessons designed for beginners and developers.

COURSE SYLLABUS
1. Introduction to SQL Server
Introduction to SQL Server SQL Server Installation SQL Server Fundamentals
2. Data Types
Data Types Numeric Data Types Character & String Data Types Date & Time Data Types Other SQL Server Data Types
3. Database & Tables
Database & Tables Introduction Creating a Database Creating Tables Table Structure Altering Tables Dropping Tables
4. Constraints
Constraints Introduction PRIMARY KEY FOREIGN KEY UNIQUE Constraint NOT NULL & DEFAULT CHECK Constraint
5. SQL Basics
SQL Basics Introduction SQL Commands SQL Command Categories SELECT Statement INSERT, UPDATE & DELETE
6. CRUD Operations
CRUD Operations Introduction INSERT Operation SELECT Operation UPDATE Operation DELETE Operation
7. SQL Queries
Queries Introduction WHERE Clause ORDER BY Clause DISTINCT LIKE Operator IN, BETWEEN & IS NULL
8. Joins
Joins Introduction INNER JOIN LEFT JOIN RIGHT JOIN FULL OUTER JOIN CROSS JOIN
9. SQL Functions
SQL Functions Introduction String Functions Numeric Functions Date & Time Functions Conversion Functions NULL Functions
10. Grouping & Aggregate Functions
GROUP BY Aggregate Functions COUNT() SUM() AVG() MIN() & MAX()
11. Subqueries
Subqueries Introduction Single-Row Subquery Multiple-Row Subquery Correlated Subquery Subquery with DML
12. Views
SQL Views Introduction Creating a View Updating a View Altering a View Dropping a View
13. Stored Procedures
Stored Procedures Introduction Creating a Stored Procedure Input Parameters Output Parameters Executing & Modifying Stored Procedures
14. Triggers
Triggers Introduction AFTER INSERT Trigger AFTER UPDATE Trigger AFTER DELETE Trigger INSTEAD OF Trigger
15. Transactions
Transactions Introduction COMMIT ROLLBACK SAVEPOINT Transaction with TRY...CATCH
16. Indexes
Indexes Introduction Clustered Index Non-Clustered Index Creating & Dropping Indexes Index Performance
17. Common Table Expressions
CTE Introduction Simple CTE CTE with JOIN CTE with Aggregate Functions Recursive CTE
18. Window Functions
Window Functions Introduction ROW_NUMBER() RANK() and DENSE_RANK() LEAD() and LAG() PARTITION BY
19. Advanced SQL
Advanced SQL Introduction Temporary Tables Table Variables Dynamic SQL Error Handling Performance Optimization

IN, BETWEEN & IS NULL

IN, BETWEEN and IS NULL are commonly used SQL operators for filtering and checking data in SQL Server.

These operators make it easier to write conditions when working with multiple values, ranges and NULL values.

IN Operator

The IN operator is used to check whether a value matches any value from a specified list.

It is useful when we want to check multiple possible values without writing several OR conditions.

IN Syntax

SQL
SELECT column_name
FROM table_name
WHERE column_name IN (value1, value2, value3);

Example Table

StudentId StudentName Age City Fees
101 Rahul 22 Pune 35000
102 Priya 23 Mumbai 40000
103 Amit 21 Nashik 30000
104 Neha 24 Pune 45000

Example – IN

Suppose we want students from Pune, Mumbai or Nashik.

SQL
SELECT *
FROM Students
WHERE City IN ('Pune', 'Mumbai', 'Nashik');

This returns records where City matches any of the specified values.

IN vs OR

The following two queries can be used to check the same set of city values.

SQL
SELECT *
FROM Students
WHERE City = 'Pune'
   OR City = 'Mumbai'
   OR City = 'Nashik';

Using IN can make this type of condition shorter and easier to read.

NOT IN

The NOT IN operator returns records whose value does not match any value in the specified list.

SQL
SELECT *
FROM Students
WHERE City NOT IN ('Pune', 'Mumbai');

This excludes students from Pune and Mumbai.

BETWEEN Operator

The BETWEEN operator is used to select values within a specified range.

BETWEEN includes both the starting and ending values.

BETWEEN Syntax

SQL
SELECT column_name
FROM table_name
WHERE column_name BETWEEN value1 AND value2;

BETWEEN with Numbers

Suppose we want students whose age is between 21 and 23.

SQL
SELECT *
FROM Students
WHERE Age BETWEEN 21 AND 23;

This includes students with ages 21, 22 and 23.

BETWEEN with Fees

SQL
SELECT *
FROM Students
WHERE Fees BETWEEN 30000 AND 40000;

This returns students whose fees are between 30000 and 40000, including both boundary values.

NOT BETWEEN

The NOT BETWEEN operator returns values outside the specified range.

SQL
SELECT *
FROM Students
WHERE Age NOT BETWEEN 21 AND 23;

This returns students whose age is outside the range 21 to 23.

IS NULL

NULL represents a missing, unknown or unavailable value.

To check whether a column contains NULL, we use IS NULL.

SQL
SELECT *
FROM Students
WHERE City IS NULL;

This returns records where City does not contain a value.

IS NOT NULL

The IS NOT NULL condition returns records where a column contains a value.

SQL
SELECT *
FROM Students
WHERE City IS NOT NULL;

This returns records where City has a value.

Important About NULL

  • NULL means the value is missing or unknown.
  • NULL is not the same as zero.
  • NULL is not the same as an empty string.
  • Use IS NULL to check for NULL values.
  • Use IS NOT NULL to check for non-NULL values.

Combining IN and BETWEEN

IN and BETWEEN can be combined with other conditions using AND or OR.

SQL
SELECT *
FROM Students
WHERE City IN ('Pune', 'Mumbai')
AND Age BETWEEN 21 AND 24;

This returns students from Pune or Mumbai whose age is between 21 and 24.

IN vs BETWEEN vs IS NULL

Operator Purpose Example
IN Checks multiple specific values. City IN ('Pune', 'Mumbai')
BETWEEN Checks values within a range. Age BETWEEN 21 AND 24
IS NULL Checks for missing NULL values. City IS NULL
IS NOT NULL Checks for values that are not NULL. City IS NOT NULL

Important Points

  • IN checks a value against multiple values.
  • NOT IN excludes specified values.
  • BETWEEN checks a range and includes both boundary values.
  • NOT BETWEEN checks values outside a range.
  • IS NULL checks for NULL values.
  • IS NOT NULL checks for non-NULL values.

Summary

In this section, we learned the IN, NOT IN, BETWEEN, NOT BETWEEN, IS NULL and IS NOT NULL operators. These operators are useful for filtering SQL Server data using multiple values, ranges and NULL checks.