SQL Equal To Operator
The SQL =
(Equal To) operator is used to filter records where a specified column’s value exactly matches a given value. This operator is commonly used in the WHERE
clause of SQL queries to retrieve specific records that meet the exact condition.
In this tutorial, we will explore the SQL Equal To operator, its syntax, and practical examples.
Syntax of SQL Equal To (=) Operator
The basic syntax of the =
operator in SQL is as follows:
</>
Copy
SELECT column1, column2, ...
FROM table_name
WHERE column_name = value;
Each part of this syntax has a specific purpose:
- SELECT: Specifies the columns to retrieve from the table.
- FROM: Specifies the table from which to retrieve data.
- WHERE: Introduces the condition used to filter records.
- =: Ensures that only records where
column_name
exactly matchesvalue
are returned.
Step-by-Step Examples Using SQL Equal To (=) Operator
1. Selecting a Specific Record from a Table
Let’s create a students
table to demonstrate the =
operator:
</>
Copy
CREATE TABLE students (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(50),
age INT,
grade VARCHAR(10)
);
Insert some sample data:
</>
Copy
INSERT INTO students (name, age, grade)
VALUES
('Arjun', 14, '8th'),
('Ram', 15, '9th'),
('John', 14, '8th'),
('Priya', 16, '10th');
Now, let’s use the =
operator to find all students in the 8th grade:
</>
Copy
SELECT * FROM students
WHERE grade = '8th';

Explanation:
- This query retrieves all records where the
grade
column is equal to'8th'
. - In this case, both Arjun and John will be displayed in the output.
2. Filtering Based on an Exact Match
Let’s say we want to retrieve details of a student named Ram
:
</>
Copy
SELECT * FROM students
WHERE name = 'Ram';

Explanation:
- This query fetches all details of the student whose
name
is exactly'Ram'
. - The result will display Ram’s
id
,age
, andgrade
.
Conclusion
In this SQL Equal To operator tutorial, we covered:
- The syntax and purpose of the
=
operator. - How to retrieve records based on an exact match.
- Practical examples using a
students
table.