Vidyalelo
MySQL · Q707

MySQL

Programming · MySQL · question 707

Q707

Which of the following WHERE clauses are faster? 1. WHERE col * 3 < 9 2. WHERE col < 9 / 3

A.
1
B.
2
Answer
C.
same speed
D.
dependent on operating system

Answer: Option B

Solution

Answer: Option B
Solution:
This question is about how MySQL handles calculations in a WHERE clause. Think of it like this: MySQL wants to be as efficient as possible when searching for data.

In option 1, WHERE col * 3 < 9, MySQL needs to multiply every value in the 'col' column by 3 before comparing it to 9. This means it does extra work for each row.

In option 2, WHERE col < 9 / 3, MySQL only needs to do the calculation (9 / 3 = 3) once. Then, it can simply compare the 'col' column values directly to 3. This is much faster!

So the answer is Option B: 2. Option 2 is faster because it performs the calculation only once, while Option 1 performs a calculation for each row.