SQL Equals To

Anonymous contributor's avatar
Anonymous contributor
Published Aug 29, 2024

The EQUAL TO operator is used to compare the equality of two expressions, used with the WHERE clause.

  • Learn to analyze data with SQL and prepare for technical interviews.
    • Includes 9 Courses
    • With Certificate
    • Beginner Friendly.
      17 hours
  • Learn how to query SQL databases and design relational databases to efficiently store large quantities of data.
    • Includes 5 Courses
    • With Certificate
    • Beginner Friendly.
      13 hours

Syntax

SELECT column1, column2, ...
FROM table_name
WHERE column1 = condition;

The equal to operator = can be combined with other comparison operators to check for the following:

  • >=: Greater than or equal to
  • <=: Less than or equal to
  • !=: Not equal

Example

Return employees that have employee IDs equal to 100 in the table Employ:

# Create a table named 'employ'
CREATE TABLE employ (employ_name VARCHAR(30), employ_id INT PRIMARY KEY);
# Insert some stocks into the table
INSERT INTO employ (employ_name, employ_id) VALUES
('John', 100),
('Janet', 101),
('Joe', 102)
# Use the EQUAL TO operator to find employees with a specific ID
SELECT employ_name, employ_id FROM employ WHERE employ_id = '100';

The query results with the following result:

employ_name, employ_id
'John', 100

All contributors

Learn SQL on Codecademy

  • Learn to analyze data with SQL and prepare for technical interviews.
    • Includes 9 Courses
    • With Certificate
    • Beginner Friendly.
      17 hours
  • Learn how to query SQL databases and design relational databases to efficiently store large quantities of data.
    • Includes 5 Courses
    • With Certificate
    • Beginner Friendly.
      13 hours