Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

SQL Query Interview Questions and Answers

Ques 31. Explain the purpose of the SQL CASE statement.

The CASE statement is used to perform conditional logic within a SQL query, similar to an IF-THEN-ELSE statement in other programming languages.

Example:

SELECT column1, CASE WHEN condition THEN 'Result1' ELSE 'Result2' END AS NewColumn FROM table;

Is it helpful? Add Comment View Comments
 

Ques 32. What is a subquery? Provide an example.

A subquery is a query embedded within another query. It can be used to retrieve data that will be used in the main query. Example: SELECT column FROM table WHERE column IN (SELECT column FROM another_table);

Is it helpful? Add Comment View Comments
 

Ques 33. Explain the difference between CHAR and VARCHAR data types.

CHAR is a fixed-length string data type, while VARCHAR is a variable-length string data type. CHAR pads spaces to the maximum length, while VARCHAR only stores the actual data without padding.

Is it helpful? Add Comment View Comments
 

Ques 34. Write a SQL query to find the total count of rows in each table of a database.

SELECT table_name, COUNT(*) FROM information_schema.tables GROUP BY table_name;

Is it helpful? Add Comment View Comments
 

Ques 35. Explain the purpose of the SQL HAVING clause.

The HAVING clause is used to filter the results of aggregate functions in a SELECT statement based on specified conditions.

Example:

SELECT column, COUNT(*) FROM table GROUP BY column HAVING COUNT(*) > 1;

Is it helpful? Add Comment View Comments
 

Most helpful rated by users:

©2025 WithoutBook