Using Comparison Operators.
Comparison operators in SQL allow you to compare values and filter results in queries. They are fundamental for working with data efficiently.
-
=: Equal to. -
!=or<>: Not equal to. -
<: Less than. -
>: Greater than. -
<=: Less than or equal to. -
>=: Greater than or equal to.
Syntax
The basic syntax for using comparison operators in SQL is:SELECT * FROM [table] WHERE [column] [operator] [value];
Comparison operators include: =, >, <, >=, <=, and <> (not equal).
Purpose
Comparison operators are essential for filtering results in SQL queries. For example, they allow you to:
- Select products with a price greater than 100.
- Find users whose age is less than 30.
- Filter records where the stock is equal to zero.
Exercises
Interactive Test 1: Drag and Drop
Drag in the corresponding order.
Drag the options:
SELECT
>
*
10
FROM
Completa el código:
______
______
______
______
______
Interactive Test 2: Fill in the Blanks
Rellena los huecos en cada casilla.
SELECT * FROM products WHERE price ;
Practical Exercise:
Statement:
Write an SQL query to select all products with a price greater than 50.
Datos de Ejemplo
| id | name | age |
|---|---|---|
| 1 | Juan | 25 |
| 2 | Ana | 30 |
| 3 | Luis | 22 |
| 4 | Marta | 35 |
* Escribe tu consulta SQL y ejecuta para ver los resultados.
Resultados:
No hay resultados disponibles.