0
0
MySQLquery~10 mins

Comparison operators in MySQL - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Comparison operators
Start with two values
Choose comparison operator
Compare values
Result: TRUE or FALSE
Use result in query condition
Comparison operators compare two values and return TRUE or FALSE, which helps filter data in queries.
Execution Sample
MySQL
SELECT * FROM employees WHERE salary > 50000;
This query selects employees whose salary is greater than 50000.
Execution Table
StepEmployee IDSalaryCondition (salary > 50000)Result (Include Row)
11014800048000 > 50000FALSE
21025200052000 > 50000TRUE
31035000050000 > 50000FALSE
41047500075000 > 50000TRUE
51053000030000 > 50000FALSE
Exit--No more rowsQuery ends
💡 All rows checked; query ends after last row.
Variable Tracker
VariableStartAfter 1After 2After 3After 4After 5Final
Current Employee ID-101102103104105-
Current Salary-4800052000500007500030000-
Condition Result-FALSETRUEFALSETRUEFALSE-
Key Moments - 2 Insights
Why does salary = 50000 return FALSE for the condition salary > 50000?
Because > means strictly greater than, so 50000 is not greater than 50000. See execution_table row 3.
What happens if the condition is FALSE for a row?
That row is not included in the query result. See execution_table rows 1, 3, and 5 where result is FALSE.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the condition result for Employee ID 104?
ATRUE
BFALSE
CNULL
DError
💡 Hint
Check the row with Employee ID 104 in the execution_table under 'Condition Result'.
At which step does the condition salary > 50000 become FALSE for the first time?
AStep 3
BStep 2
CStep 1
DStep 4
💡 Hint
Look at the 'Condition Result' column in execution_table for the earliest FALSE.
If the operator changed to salary >= 50000, how would the result for Employee ID 103 change?
AIt would remain FALSE
BIt would become TRUE
CIt would cause an error
DIt would be NULL
💡 Hint
Check the difference between > and >= operators in the key_moments section.
Concept Snapshot
Comparison operators compare two values and return TRUE or FALSE.
Common operators: =, !=, <, >, <=, >=.
Used in WHERE clauses to filter rows.
Example: salary > 50000 selects rows with salary greater than 50000.
Equal (=) checks exact match; greater than (>) checks if left is bigger.
Results control which rows appear in query output.
Full Transcript
Comparison operators in SQL compare two values and return TRUE or FALSE. This helps decide which rows to include in query results. For example, the operator > means 'greater than'. If we write WHERE salary > 50000, only employees with salary more than 50000 are selected. In the example, employee with salary 48000 is excluded because 48000 is not greater than 50000. Employee with salary 52000 is included because 52000 is greater than 50000. The operator = means equal, and >= means greater than or equal. Understanding these operators helps filter data effectively.