Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

95
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda