Question : Which clause is used to filter records in SQL?
Solution :
Correct Answer : WHERE
Description -
Question : Which operator is used to combine multiple conditions where all conditions must be true?
Solution :
Correct Answer : AND
Description -
Question : Which operator returns records if at least one condition is true?
Solution :
Correct Answer : OR
Description -
Question : Which clause is used with aggregate functions to filter grouped data?
Solution :
Correct Answer : HAVING
Description -
Question : Which keyword is used to create a temporary result set in SQL?
Solution :
Correct Answer : WITH
Description -
Question : What is the purpose of the AS keyword?
Solution :
Correct Answer : Rename column/table temporarily
Description -
Question : Which query correctly uses the WHERE clause?
Solution :
Correct Answer : SELECT * FROM Student WHERE Marks>50;
Description -
Question : What will the following query return?
SELECT * FROM Product
WHERE Price > 100 AND Quantity > 10;
Solution :
Correct Answer : Products with both conditions true
Description -
Question : Which clause cannot be used without GROUP BY?
Solution :
Correct Answer : HAVING
Description -
Question : Which SQL statement uses OR correctly?
Solution :
Correct Answer : SELECT * FROM Student WHERE City='Patna' OR Age>20;
Description -
Question : Which clause executes before HAVING?
Solution :
Correct Answer : GROUP BY
Description -
Question : Which keyword is used for column aliasing?
Solution :
Correct Answer : AS
Description -
Question : What is the output of:
SELECT COUNT(*) AS Total
FROM Employee;
Solution :
Correct Answer : Counts rows
Description -
Question : Which clause filters rows before grouping?
Solution :
Correct Answer : WHERE
Description -
Question : Which clause filters groups after grouping?
Solution :
Correct Answer : HAVING
Description -
Question : Which query finds employees from HR department earning more than 40000?
Solution : SELECT * FROM Employee
Correct Answer :
WHERE Department='HR' AND Salary>40000;
Description -
Question : Which statement about WITH clause is true?
Solution :
Correct Answer : Creates temporary result set
Description -
Question : Which query uses HAVING correctly?
Solution : SELECT Department, AVG(Salary)
Correct Answer :
FROM Employee
GROUP BY Department
HAVING AVG(Salary)>50000;
Description -
Question : Which operator has higher priority?
Solution :
Correct Answer : AND
Description -
Question : Which keyword gives a temporary name to a table?
Solution :
Correct Answer : AS
Description -
Question : What does the following query do? SELECT * FROM Student
WHERE NOT Age = 18;
Solution :
Correct Answer : Selects students not aged 18
Description -
Question : Which clause is used with aggregate functions?
Solution :
Correct Answer : HAVING
Description -
Question : Which query uses Common Table Expression (CTE) correctly?
Solution : WITH Temp AS (
Correct Answer :
SELECT * FROM Employee
)
SELECT * FROM Temp;
Description -
Question : Which keyword is optional while aliasing columns in many databases?
Solution :
Correct Answer : AS
Description -
Question : Which query returns employees from IT or Finance?
Solution : SELECT * FROM Employee
Correct Answer :
WHERE Department='IT' OR Department='Finance';
Description -
Question : What is wrong in the query?
SELECT Department, COUNT(*)
FROM Employee
HAVING COUNT(*)>2;
Solution :
Correct Answer : HAVING used without GROUP BY
Description -
Question : Which clause can contain aggregate functions directly?
Solution :
Correct Answer : HAVING
Description -
Question : Which condition is evaluated first? WHERE Marks>80 OR Grade='A' AND Age<20
Solution :
Correct Answer : AND condition
Description -
Question : Which query gives alias to a table?
Solution :
Correct Answer : SELECT * FROM Employee AS E;
Description -
Question : Which statement is true about WHERE and HAVING?
Solution :
Correct Answer : WHERE filters rows, HAVING filters groups
Description -
SELECT Department, COUNT(*)
FROM Employee
WHERE Salary > 30000
GROUP BY Department
HAVING COUNT(*) > 2;