Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

100
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!