Skip to content

SQL Filtering Essentials Quiz Revision

Quiz revision for WHERE, NULL, patterns, ranges, and logical conditions.

Builds on SQL Filtering Essentials and Filtering Essentials in Detail

Stage 1core4 min read

Comparisons such as salary != NULL are syntactically accepted but evaluate to UNKNOWN; use IS 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 != NULL
  • salary <> NULL
  • salary IS NOT NULL
  • salary NOT NULL

Correct Answer

salary IS NOT NULL

Explanation

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 <> NULL

To check whether a value exists, SQL uses:

IS NOT NULL

Use:

  • IS NULL → find missing values
  • IS NOT NULL → find existing values

Question 2

Which operator is used to match a list of values?

Options

  • BETWEEN
  • LIKE
  • IN
  • EXISTS

Correct Answer

IN

Explanation

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 ranges
  • LIKE → used for pattern matching
  • EXISTS → 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 string A%
  • name LIKE '%A' → ends with A
  • name 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

idnamesalaryagedepartmentbonus
1Amit5000028IT5000
2Neha6000035HRNULL
3Rahul4500025IT3000
4Pooja7000040FinanceNULL
5Karan6000030IT6000

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 before
  • a → 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

idnamesalaryagedepartmentbonus
1Amit5000028IT5000
2Neha6000035HRNULL
3Rahul4500025IT3000
4Pooja7000040FinanceNULL
5Karan6000030IT6000

Options

  • Rahul
  • Amit, Rahul
  • Neha, Pooja
  • No rows

Correct Answer

Amit, Rahul

Explanation

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 40

This returns rows outside that range.

Included:

  • Amit (28)
  • Rahul (25)

Final Quick Revision

QuestionCorrect Answer
Q1salary IS NOT NULL
Q2IN
Q3%
Q4name LIKE 'A%'
Q5All employees (with a case-insensitive collation)
Q6Amit, Rahul

One-Line Memory Trick

  • IS NOT NULL → value exists
  • IN → one from list
  • % → any characters
  • A% → starts with A
  • %a% → contains a
  • NOT BETWEEN → outside range

In this topic

Done with this topic?

How well do you know it?

PreviousBasic SQL MCQ Revision