Remember that
SELECT name salary FROM employeesis commonly parsed asname AS salary; it is ambiguous style, not necessarily a missing-comma syntax error.
1. Select only specific columns
Question
Which query selects only the name and salary columns?
Correct Answer
SELECT name, salary FROM employees;Explanation
To fetch only specific columns, write the column names after SELECT separated by commas.
SELECTchooses columnsFROM employeestells SQL which table to read
Why others are wrong
SELECT (name, salary)→ invalid syntaxSELECT name salary→ parsed by many databases asname AS salary; valid but unclear styleSELECT * name, salary→ invalid syntax
2. Purpose of DISTINCT
Question
What is the purpose of DISTINCT in a SELECT statement?
Correct Answer
Removes duplicate rows
Explanation
DISTINCT returns only unique values and removes duplicates from the result.
Example
SELECT DISTINCT city FROM customers;If multiple customers belong to the same city, each city appears only once.
3. Clause used to filter rows
Question
Which clause is used to filter rows?
Correct Answer
WHERE
Explanation
WHERE filters rows based on a condition.
Example
SELECT * FROM employees
WHERE salary > 50000;Only rows matching the condition are returned.
4. If no rows satisfy WHERE
Question
What is the output if no rows satisfy the WHERE condition?
Correct Answer
Empty result set
Explanation
If no rows match the condition:
- SQL does not throw an error
- SQL does not return
NULL - SQL returns 0 rows
This is called an empty result set.
Example
SELECT * FROM employees
WHERE salary > 1000000;If no employee matches, output is simply empty.
5. Comparing with NULL using =
Question
What is the output of:
SELECT name
FROM employees
WHERE bonus = NULL;Correct Answer
No rows
Explanation
This is one of the most common SQL traps.
At first glance, it looks like this should return employees whose bonus is NULL (Neha and Pooja), but it does not.
In SQL, NULL means unknown or missing value.
So this condition:
bonus = NULLdoes not check whether bonus is empty.
It asks:
“Is bonus equal to an unknown value?”
That comparison is never true.
So SQL returns no rows.
Correct way
SELECT name
FROM employees
WHERE bonus IS NULL;Correct Output
Neha, Pooja
Rule to remember
= NULLis wrong!= NULLis wrongIS NULLis correctIS NOT NULLis correct
6. Not equal operator (<>)
Question
What is the output of:
SELECT name
FROM employees
WHERE salary <> 60000;Correct Answer
Amit, Rahul, Pooja
Explanation
<> means not equal to.
So SQL returns employees whose salary is not 60000.
Check
- Amit → 50000 → yes
- Neha → 60000 → no
- Rahul → 45000 → yes
- Pooja → 70000 → yes
- Karan → 60000 → no
Output
Amit, Rahul, Pooja
7. Multiple conditions with AND
Question
What is the output of:
SELECT name
FROM employees
WHERE salary * 2 >= 120000 AND age < 35;Correct Answer
Karan
Explanation
Both conditions must be true:
salary * 2 >= 120000age < 35
Check
- Amit → 100000 → no
- Neha → 120000 yes, but age = 35 → no
- Rahul → 90000 → no
- Pooja → 140000 yes, but age = 40 → no
- Karan → 120000 yes and age = 30 yes
Output
Karan
8. Arithmetic with NULL
Question
What is the output of:
SELECT name
FROM employees
WHERE (salary + bonus) > 65000;Correct Answer
Karan only
Explanation
If any value in arithmetic is NULL, the result becomes NULL.
salary + NULL = NULLAnd:
NULL > 65000is not true.
So rows with NULL bonus are ignored.
Check
- Amit → 50000 + 5000 = 55000 → no
- Neha → 60000 + NULL = NULL → no
- Rahul → 45000 + 3000 = 48000 → no
- Pooja → 70000 + NULL = NULL → no
- Karan → 60000 + 6000 = 66000 → yes
Output
Karan only
Quick Revision Summary
| Topic | Key Point |
|---|---|
| Select specific columns | Use column names separated by commas |
| DISTINCT | Removes duplicate rows |
| WHERE | Filters rows |
| No match in WHERE | Returns empty result set |
= NULL | Always returns no rows |
IS NULL | Correct way to check NULL |
<> | Not equal to |
AND | Both conditions must be true |
| Arithmetic with NULL | Result becomes NULL |