SQL Where-interview
Scenario 1: Basic Filtering
From your company's database, you wish to view employees who are precisely 32 years old.
Interview Question
In what ways does SQL's WHERE clause assist?
Answer:
It uses a specified condition to filter records:
Scenario 2: Filtering on Range
Interview Question
SELECT ID, NAME FROM EMPLOYEES WHERE AGE = 32;
Tips: When filtering, use = for exact matches.
Scenario 2: Filtering on Range
A list of workers making less than ₹20,000 is what you're looking for.
Interview Question
How can a criteria like "less than" be used to filter results?
Answer:
With WHERE, use the < operator:
SELECT ID, NAME FROM EMPLOYEES WHERE SALARY < 20000;
Tips: Use <, >, <=, >= for conditions involving numbers.
Scenario 3: Filtering with Multiple Conditions
Interview Question
You want workers who make more than ₹15,000 and are older than 25.
Interview Question
How may the WHERE clause be used to apply several conditions?
Answer:
Utilize AND/OR to merge:
SELECT * FROM EMPLOYEES WHERE AGE > 25 AND SALARY > 15000;
Tips: When dealing with complex conditions that contain both AND and OR, use brackets ().