Comparisons such as
salary != NULLare syntactically accepted but evaluate toUNKNOWN; useIS NOT NULL. Case-sensitive answers depend on the column's collation.
Question 1
Which query correctly finds rows where salary is not NULL?
Options
salary != NULLsalary <> NULLsalary IS NOT NULLsalary NOT NULL
Correct Answer
salary IS NOT NULLExplanation
NULL means unknown or missing value.
Because NULL represents an unknown or missing value, direct comparisons with these operators do not return TRUE:
=!=<>
These expressions evaluate to UNKNOWN:
salary != NULL
salary <> NULLTo check whether a value exists, SQL uses:
IS NOT NULLUse:
IS NULL→ find missing valuesIS NOT NULL→ find existing values
Question 2
Which operator is used to match a list of values?
Options
BETWEENLIKEINEXISTS
Correct Answer
INExplanation
The IN operator checks whether a value matches any value from a list.
Example:
SELECT *
FROM users
WHERE city IN ('Delhi', 'Mumbai', 'Pune');This means:
Return rows where city is Delhi, Mumbai, or Pune.
Why others are wrong:
BETWEEN→ used for rangesLIKE→ used for pattern matchingEXISTS→ checks whether a subquery returns rows
Question 3
Which wildcard is used with LIKE to match any number of characters?
Options
_%?
Correct Answer
%Explanation
In SQL LIKE:
%→ matches any number of characters_→ matches exactly one character
Example:
WHERE name LIKE 'A%'Matches:
- Amit
- Aayush
- Ananya
Because % means:
anything can come after A
Why others are wrong:
_→ exactly one character- → not SQL wildcard
?→ not SQL wildcard
Question 4
Which condition matches names starting with ‘A’?
Options
name = 'A%'name LIKE 'A%'name LIKE '%A'name LIKE '_A'
Correct Answer
name LIKE 'A%'Explanation
To find names starting with A, use:
LIKE 'A%'This means:
- starts with
A - followed by anything
Matches:
- Amit
- Aayush
- Ananya
Why others are wrong:
name = 'A%'→ checks exact stringA%name LIKE '%A'→ ends with Aname LIKE '_A'→ exactly 2-letter names ending in A
Question 5
What is the output?
SELECT name
FROM employees
WHERE name LIKE '%a%';Employees Table
| id | name | salary | age | department | bonus |
|---|---|---|---|---|---|
| 1 | Amit | 50000 | 28 | IT | 5000 |
| 2 | Neha | 60000 | 35 | HR | NULL |
| 3 | Rahul | 45000 | 25 | IT | 3000 |
| 4 | Pooja | 70000 | 40 | Finance | NULL |
| 5 | Karan | 60000 | 30 | IT | 6000 |
Options
- Amit, Rahul, Karan
- Rahul, Karan
- Amit, Neha, Rahul, Karan
- All employees (with a case-insensitive collation)
Correct Answer
All employees (with a case-insensitive collation)Explanation
The condition is:
name LIKE '%a%'This means:
return names containing letter a anywhere in the string
Pattern breakdown:
%→ anything beforea→ required character%→ anything after
Now check each row:
- Amit → contains
A/a - Neha → contains
a - Rahul → contains
a - Pooja → contains
a - Karan → contains
a
So every employee name contains the letter a.
Final Output
- Amit
- Neha
- Rahul
- Pooja
- Karan
That means:
All employees (with a case-insensitive collation)Question 6
What is the output?
SELECT name
FROM employees
WHERE age NOT BETWEEN 30 AND 40;Employees Table
| id | name | salary | age | department | bonus |
|---|---|---|---|---|---|
| 1 | Amit | 50000 | 28 | IT | 5000 |
| 2 | Neha | 60000 | 35 | HR | NULL |
| 3 | Rahul | 45000 | 25 | IT | 3000 |
| 4 | Pooja | 70000 | 40 | Finance | NULL |
| 5 | Karan | 60000 | 30 | IT | 6000 |
Options
- Rahul
- Amit, Rahul
- Neha, Pooja
- No rows
Correct Answer
Amit, RahulExplanation
BETWEEN 30 AND 40 is inclusive.
That means it includes:
- 30
- 35
- 40
So this matches:
- Neha (35)
- Pooja (40)
- Karan (30)
Now apply NOT:
age NOT BETWEEN 30 AND 40This returns rows outside that range.
Included:
- Amit (28)
- Rahul (25)
Final Quick Revision
| Question | Correct Answer |
|---|---|
| Q1 | salary IS NOT NULL |
| Q2 | IN |
| Q3 | % |
| Q4 | name LIKE 'A%' |
| Q5 | All employees (with a case-insensitive collation) |
| Q6 | Amit, Rahul |
One-Line Memory Trick
IS NOT NULL→ value existsIN→ one from list%→ any charactersA%→ starts with A%a%→ contains aNOT BETWEEN→ outside range