Comprehensive Data Analyst Interview Prep - SQL Topics
This document consolidates all essential SQL interview questions and answers based on the
comprehensive training content provided in the source material. It covers conceptual definitions,
query-writing tasks, scenario-based situations, and assessment-style interview questions.
Conceptual SQL Commands and Syntax
- Define DDL, DML, TCL, and DCL commands with examples.
- What are constraints in SQL? Explain NOT NULL, UNIQUE, PRIMARY KEY, FOREIGN KEY.
- Difference between DELETE and TRUNCATE.
- What is a view in SQL and its uses?
- Explain types of joins: INNER, LEFT, RIGHT, FULL, CROSS JOIN.
Scenario-Based Situational Questions
- How would you fetch the 3rd highest salary in a table?
- What would you do to clean duplicate records keeping one entry?
- How to fetch employees whose salary is above department average?
- How to track inserted, updated, and deleted data in a log table using triggers?
- Write a SQL merge query to synchronize two tables.
Query-Writing Challenges
- Write a query to extract distinct cities from an Employee table.
- Fetch running total of Salary within each department.
- Get top 2 highest salaries per department.
- Pick names starting with 'R' or 'S'.
- Extract First_Name, Middle_Name, Last_Name from a full Name field.
SQL Functions & String Handling
- Use LEN, UPPER, LOWER, LEFT, RIGHT, REPLACE, SUBSTRING with examples.
- Explain GETDATE(), DATEDIFF(), DATEADD() functions.
- What's the difference between CONVERT and CAST?
Indexing and Performance Optimization
- Define clustered and non-clustered indexes with examples.
- How would you improve query performance for a large Employee table?
- Explain how CTE (Common Table Expression) works.
Stored Procedures, Triggers, and Cursors
- Create a parameterized stored procedure.
- Explain the difference between stored procedure and function.
- Create an after insert, update, delete trigger to log data.
- Explain cursor use cases and write a scroll cursor example.