SQL Interview Questionnaire
1. How would you assess your proficiency in SQL, on a scale from 1 to 10?
Example Response: Currently, I would rate my SQL skills at an 8 out of 10.
2. Can you elaborate on your experience with SQL, both in your current role and in
previous positions?
Example Response: In my current role, SQL is integral to my daily tasks. I utilize it extensively
for querying tables and views to extract and analyze data. Additionally, I'm responsible for
creating Stored Procedures to automate report generation and distribution to clients.
Collaborating with the programming team, I optimize SQL scripts for enhanced performance.
Moreover, I employ SQL for data acquisition, cleansing, and modeling to support product
development.
3. Have you utilized any Cloud-based platforms? If yes, please explain how you've
leveraged them.
Example Response: Indeed, I have experience with Azure, and in the past, I've also worked with
AWS. Within Azure, I utilize DataLake for storing vast datasets efficiently. Furthermore, I
employ Databricks to automate the ingestion process of flat files received from clients,
streamlining data handling procedures.
General Questions
1. Can you tell me about a difficult project you worked on as a data analyst?
Example Response: One challenging project happened in March when we needed
to submit data for MIPS, a program for one of our major clients. We faced a tight
deadline, but one of our contract workers from Canada, who was crucial for
analyzing a large dataset, couldn't be reached. In a pinch, I teamed up with our
Director of Data Analytics and pulled an all-nighter to ensure we met the deadline.
Despite the hurdles, we successfully delivered the analytics on time.
2. Have you ever collaborated with a team on a data analysis project?
Example Response: Absolutely, we once collaborated with a client in North
Carolina to conduct a Gap Analysis between their existing on-premises system and
a new Cloud-based system. It involved coordination between our team and theirs,
working on data access from different locations. Our team leader delegated tasks,
and over several weeks, we provided them with a comprehensive analysis.
3. Are you familiar with cloud platforms?
Example Response: Yes, I'm well-versed in Azure and have some exposure to AWS.
While I've taken courses on Google Cloud Platform (GCP), I haven't yet had the
chance to apply it in a professional capacity.
4. Can you share an instance where you made a mistake on a project and how
you resolved it?
Example Response: Once, while analyzing data for a client, I mistakenly used data
from our historical server instead of the updated one receiving daily feeds. The
client noticed discrepancies, and I promptly admitted the error, promising to
provide an analysis with the correct data. Fortunately, our good rapport helped,
and the client was understanding. I quickly rectified the mistake and met our
deadline, ensuring accurate results were delivered.
SQL Face-to-Face Interview Questions
Beginner Level
1. Can you explain the difference between a table and a view?
Example Answer: Sure! A table is like a storage box where we keep our data in a
database. It's where the actual information is stored. On the other hand, a view is
like a virtual table. It's not a physical storage like a table but a saved query result
that we can treat as a table. It's like a window through which we can see a subset
of data from one or more tables.
2. How do you write a query to select only unique records in a column?
Example Answer: To pick out unique records from a column, we use the DISTINCT
keyword in our SELECT statement. So, the query would look like this:
```sql
SELECT DISTINCT(Column)
FROM Table;
```
3. I have two columns: Drug_Name and Drug_Price. Each drug has different
prices depending on where it is sold. How would you find the drug name with
the highest price it is being sold at?
Answer: We can use the MAX() function to find the highest price and pair it with
the drug name. Here's how the query would look:
```sql
SELECT Drug_Name, MAX(Drug_Price)
FROM table
GROUP BY Drug_Name;
```
4. What does the GROUP BY statement do in a query? And why would you use
it?
Example Answer: The GROUP BY statement helps organize our data by grouping
rows with the same values together. It's typically used with aggregate functions
like SUM(), COUNT(), AVG(), etc. This way, we can summarize data and analyze it
more efficiently.
5. I have a column called Drug_Name. I want to retrieve only the drug names
that start with "Aspirin". How would you do that using the "LIKE" operator?
Answer: We can use the LIKE operator along with the '%' wildcard to find drug
names that start with "Aspirin". Here's the query:
```sql
SELECT Drug_Name
FROM table
WHERE Drug_Name LIKE 'Aspirin%';
```
Intermediate Level SQL Interview Questions
1. Can you explain what a subquery is and how you would write one?
Example Answer: Absolutely! A subquery is like a mini-query nested inside a
larger query. It helps us retrieve specific data based on conditions. Here's how I'd
write one:
```sql
SELECT *
FROM Table
WHERE UserID IN
(SELECT userID
FROM Table2);
```
2. What is a join, and what kind of data does an inner join return?
Example Answer: A join brings together data from two tables into a single result.
An inner join specifically returns data that is common between both tables. For
instance, if Table 1 has items a, b, and c, and Table 2 has items b and c, only items
b and c will be returned because they exist in both tables.
3. How do inner and outer joins differ?
Example Answer: An inner join fetches data that overlaps between both tables,
whereas an outer join brings back all the records from one table plus the matching
records from the other table. In other words, an outer join doesn't require a
match for every row, whereas an inner join does.
4. What is a CASE statement, and how do you use it?
Example Answer: Think of the CASE statement like a decision-maker in SQL. It
evaluates conditions and returns a value when a condition is met, similar to an
IF-THEN-ELSE statement. Here's how you can write it:
```sql
SELECT CASE
WHEN column > 2 THEN 'Output1'
ELSE 'Output2'
END
FROM Table;
```
5. Can you explain the UNION operator and demonstrate how to use it?
Example Answer: Sure! The UNION operator combines the results of two or more
SELECT statements. It removes duplicates by default. Here's an example of how to
write it:
```sql
SELECT Column1, Column2
FROM Table1
UNION
SELECT Column1, Column2
FROM Table2;
```
6. Suppose we have two tables: one for patient information and the other for
drug information. Can you create a query to retrieve PatientID, Disease, and
Dispensed_drug?
Answer:
```sql
SELECT [Link], Disease, Dispensed_Drug
FROM Patient
JOIN Drug
ON [Link] = [Link];
```
Challenging SQL Interview Questions
1. Can you explain what sys tables or System tables are?
Example Answer: Absolutely! [Link] is a special table used by the database to
keep track of all the other tables in the database. It holds important details like
the name of each table, when it was created, and when it was last changed. Each
table in the database has just one entry in [Link]. We often use the unique ID
of each table, called the Object ID, to link it with other system tables like
[Link] to get more details about the table's columns.
2. What does the ISNULL function do?
Example Answer: The ISNULL function is like a safety net in SQL. It checks if a value
is NULL. If it is, it replaces it with another value you specify. But if the value isn't
NULL, it leaves it unchanged.
3. Can you explain what a temp table is and how you would use it?
Example Answer: Sure thing! A temp table is like a temporary storage space in SQL
Server. It's a table that only exists for a little while, usually just for the duration of
a session or a task. You create it when you need to work with some data
temporarily. First, you define the table with its columns and data types. Then, you
load data into it from another table or with some specific values. Once you're
done using it, the temp table goes away. It's handy for when you need to
manipulate data but don't want to change the original table.