Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

93
Vistas
Execution order of an non-typical My-SQL Query

Assuming we've got table with following schema:

create table Test(id integer, title varchar(100));
insert into Test(id, title) values(1, "Hello");
insert into Test(id, title) values(20, "Hi");

Non-typical query in that case would be :

select * from Test where id= 20 < 2 AND SLEEP(1000000000) ;
-- sleep is being executed
select * from Test where id= 20 > 2 AND SLEEP(1000000000) ;
-- sleep is not being executed and nothing is going to be display
select * from Test where id = 20  > 0;
-- shows only one record , where id=20 /// "Hi"
select * from Test where id = 20  > -1;
-- shows whole table structure

Prior to this example, my question is what is happening in that specify moment of comparsion. Why it acting different if id=20 > 0 than id = 20 > -1.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Here is the query in question:

SELECT *
FROM Test
WHERE id = 20 > -1;

The reason the above returns the entire table is that the WHERE clause actually contains a range comparison, and is being evaluated as this:

SELECT *
FROM Test
WHERE (id = 20) > -1;

The expression (id = 20) will evaluate to either 1, if true, or 0, if false. In either case, both zero and one will always be greater than -1, hence this query will always return all records.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda