Govt. Exams
Entrance Exams
Advertisement
Topics in Database
Which SQL function is used to count non-NULL values in a column?
Correct Answer:
A. COUNT(column_name)
EXPLANATION
COUNT(column_name) counts the number of non-NULL values in the specified column. COUNT(*) counts all rows.
What will be the result of this query: SELECT * FROM employees WHERE salary > 50000 AND department = 'IT';
Correct Answer:
B. Only IT employees with salary greater than 50000
EXPLANATION
The AND operator requires both conditions to be true, so only employees in IT department with salary > 50000 are returned.
What is the difference between WHERE and HAVING clauses?
Correct Answer:
A. WHERE filters rows before grouping; HAVING filters groups after grouping
EXPLANATION
WHERE filters individual rows before GROUP BY is applied, while HAVING filters the grouped results after GROUP BY is applied.
Which SQL clause is used to sort the result set in ascending or descending order?
Correct Answer:
B. ORDER BY
EXPLANATION
The ORDER BY clause sorts the result set in ascending (ASC) or descending (DESC) order. Default is ascending.
Which type of JOIN returns only matching rows from both tables?
Correct Answer:
C. INNER JOIN
EXPLANATION
INNER JOIN returns only the rows that have matching values in both tables being joined.
What is the purpose of the JOIN clause in SQL?
Correct Answer:
A. To combine rows from two or more tables based on related columns
EXPLANATION
JOIN combines rows from two or more tables based on a relationship between the columns (usually foreign key relationship).