Introduction
Comparison operators help you check if values are equal, bigger, smaller, or different. This lets you find specific data in your database.
Comparison operators help you check if values are equal, bigger, smaller, or different. This lets you find specific data in your database.
value1 = value2 value1 <> value2 value1 != value2 value1 > value2 value1 < value2 value1 >= value2 value1 <= value2
= means equal to.
<> and != both mean not equal to.
SELECT * FROM employees WHERE age = 25;
SELECT * FROM products WHERE price > 50;
SELECT * FROM orders WHERE status <> 'shipped';
SELECT * FROM users WHERE signup_date <= '2023-01-01';
This creates a table of employees, adds three people, and then selects those older than 28.
CREATE TABLE employees ( id INT, name VARCHAR(50), age INT ); INSERT INTO employees (id, name, age) VALUES (1, 'Alice', 30), (2, 'Bob', 25), (3, 'Charlie', 35); SELECT name FROM employees WHERE age > 28;
Use single quotes for text values in comparisons.
Comparison operators work with numbers, text, and dates.
Remember that = checks for equality, while <> and != check for inequality.
Comparison operators let you compare values to filter data.
Common operators include =, <>, !=, >, <, >=, and <=.
They are essential for searching and sorting data in databases.
age is greater than 18 in a WHERE clause?Employees with a column salary, what will the query SELECT * FROM Employees WHERE salary <= 50000; return?SELECT * FROM Products WHERE price ! 100;Pass the test and this pattern moves unknown