0% found this document useful (0 votes)
1 views

Questionaire Set 1 - SQL 1

The document contains a series of SQL interview questions and answers, covering topics such as the differences between WHERE and HAVING clauses, handling NULL values, views, and Common Table Expressions (CTEs). It includes example SQL queries for each topic to illustrate the concepts. Additionally, there is a section for candidate evaluation and feedback on various skills.

Uploaded by

pranaentc
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Questionaire Set 1 - SQL 1

The document contains a series of SQL interview questions and answers, covering topics such as the differences between WHERE and HAVING clauses, handling NULL values, views, and Common Table Expressions (CTEs). It includes example SQL queries for each topic to illustrate the concepts. Additionally, there is a section for candidate evaluation and feedback on various skills.

Uploaded by

pranaentc
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Set -A (SQL)

Candidate Name:
Relevant Years of Exp:
Contact No:
Date:
--------------------------------------------------------------------------------------------------
----------------------

1. What is the difference between WHERE and HAVING clause? (Provide


example if any)
Answer:
WHERE clause is used to filter data row by row where as HAVING clause filters
data by groups. Usually WHERE clause is used before GROUP BY and HAVING
clause is used after GROUP BY statement to filter out data in a group.
Example: (Referring Employee table in question no 5)
1. WHERE clause –
SELECT * FROM EMPLOYEE
WHERE EmployeeID = 1;

2. HAVING clause –
SELECT * FROM EMPLOYEE
GROUP BY DepartmentID
HAVING Name = ‘Bob’;

2. How do you handle NULL values in SQL? (write the syntax)


Answer:
There are multiple ways for handling NULL values in SQL, we use them according
to our specific use case.
1. To prevent NULL values, I design a table by setting NOT NULL constraint or
Default values in the table schema.
2. Checking if there are any NULL values –
SELECT * FROM Employee WHERE EmployeeID IS NULL;
SELECT * FROM Employee WHERE EmployeeID IS NOT NULL;
3. Replacing NULL values-
UPDATE Employee
SET Name = ‘XYZ’
WHERE Name IS NULL;

3. What is the view? Please write create view syntax. (Please refer the
table in question no 5)
Answer:
A View is nothing but a virtual table which doesn’t store data itself but represents
data from one or more underlying tables. It is often used for security purpose,
simplify complex queries or represent data in more meaningful way to users.
Changes done in underlying tables are reflected in view.
Example: CREATE VIEW DEPT AS
SELECT Name, DepartmentID
FROM Employee
WHERE DepartmentID = 10;

4. What is CTE and write down syntax? (Please refer the table in question no-5)

Answer: CTE in SQL stands for ‘Common Table Expression’. It is a temporary


result set which can be used in SQL query. It reduces complexity of queries. CTEs
can be used multiple times within a single query.
Syntax: WITH cte_name AS (
SELECT column1, column2, ...
FROM table_name
WHERE condition
)

5. Write the query to populate the Department Name for the Employee names in the table.
Employee Table:

EmployeeID Name DepartmentID


1 Alice 10
2 Bob 20
3 Charlie 30
4 Diana NULL

Department:
DepartmentID DepartmentName
10 HR
20 IT
30 Finance
40 Sales

Answer:
SELECT E.Name, D.DepartmentName

FROM Employee E

JOIN Department D

ON E.DepartmentID= D.DepartmentID;
----------------------------------------------
END----------------------------------------------------------
Test Score:

Answer
Skill Answers
Format
SQL Rating (1-5)
Python Rating (1-5)
Excel Rating (1-5)
Visualization Rating (1-5)
Media/Advertising Rating (1-5)
Troubleshooting and
Rating (1-5)
Critical Thinking
Communication Rating (1-5)
Client Facing Experience Rating (1-5)
Total Experience Years

Gaps/Issue with Brief


Candidate Statement

L1 Feedback:

L2 Feedback:

Overall Feedback:

You might also like