Skip to content

Instantly share code, notes, and snippets.

@rpivo
Last active July 4, 2021 14:20
Show Gist options
  • Save rpivo/94b152ea6cb085f827ffa75e9cdfb31b to your computer and use it in GitHub Desktop.
Save rpivo/94b152ea6cb085f827ffa75e9cdfb31b to your computer and use it in GitHub Desktop.
MySQL's Not Equal Operators

MySQL's Not Equal Operators

In MySQL (and MSSQL), there are two not equal operators: != and <>.

The following SQL schema will produce the table below.

Create table If Not Exists Employees (employee_id int, name varchar(30), salary int);
Truncate table Employees;
insert into Employees (employee_id, name, salary) values ('2', 'Meir', '3000');
insert into Employees (employee_id, name, salary) values ('3', 'Michael', '3800');
insert into Employees (employee_id, name, salary) values ('7', 'Addilyn', '7400');
insert into Employees (employee_id, name, salary) values ('8', 'Juan', '6100');
insert into Employees (employee_id, name, salary) values ('9', 'Kannon', '7700');
employee_id name salary
2 Meir 3000
3 Michael 3800
7 Addilyn 7400
8 Juan 6100
9 Kannon 7700

We can use one of the not equal operators to select the name column and filter by names that do not begin with "M".

SELECT name
FROM Employees
WHERE LEFT(name, 1) <> "M";
name
Addilyn
Juan
Kannon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment