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

Arrastra en el orden correspondiente.


Arrastra las opciones:

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

idnameage
1Juan25
2Ana30
3Luis22
4Marta35

* Escribe tu consulta SQL y ejecuta para ver los resultados.

Resultados:

No hay resultados disponibles.



Which of the following is a comparison operator in SQL?