Sunday, 4 October 2026

50 Basic SQL Interview Questions and Answers for Beginners

 

If you are preparing for a Data Analyst, MIS Analyst, Reporting Analyst, Business Analyst, or SQL-related job, knowing the fundamentals of SQL is extremely important.

In this article, we will cover 50 basic SQL interview questions with simple explanations and examples. These questions are especially useful for beginners who are learning SQL for the first time or preparing for their first SQL interview.

The examples use common tables such as Employees, Departments, and Companies.


1. What is SQL?

Answer:

SQL stands for Structured Query Language. It is used to communicate with relational databases.

SQL can be used to:

  • Retrieve data

  • Insert data

  • Update data

  • Delete data

  • Create tables

  • Modify database structures

  • Analyze business data

Example:

SELECT * FROM Employees;

This query retrieves all records from the Employees table.


2. What is a Database?

A database is an organized collection of data that allows information to be stored, managed, and retrieved efficiently.

For example, a company database might contain:

  • Employees

  • Departments

  • Salaries

  • Customers

  • Orders

  • Products


3. What is a Table?

A table stores data in rows and columns.

Example:

EmployeeIDEmployeeNameDepartmentSalary
101RahulIT75000
102AmitHR65000
103NehaFinance85000

Here:

  • EmployeeID, EmployeeName, Department, and Salary are columns.

  • Each employee record is a row.


4. What is a Primary Key?

A Primary Key uniquely identifies each record in a table.

Example:

CREATE TABLE Employees (
    EmployeeID INT PRIMARY KEY,
    EmployeeName VARCHAR(100),
    Salary INT
);

Here, EmployeeID is the primary key.

A primary key:

  • Must contain unique values.

  • Cannot contain NULL values.

  • Identifies each row uniquely.


5. What is a Foreign Key?

A foreign key is a column that creates a relationship between two tables.

Example:

CREATE TABLE Employees (
EmployeeID INT PRIMARY KEY,
EmployeeName VARCHAR(100),
DepartmentID INT,
FOREIGN KEY (DepartmentID)
REFERENCES Departments(DepartmentID)
);

DepartmentID connects the Employees table with the Departments table.


6. What is SELECT in SQL?

SELECT is used to retrieve data from a table.

SELECT EmployeeName, Salary
FROM Employees;

This returns the employee name and salary.


7. How do you retrieve all columns from a table?

Use the * symbol.

SELECT *
FROM Employees;

This returns all columns.


8. What is the WHERE clause?

WHERE filters records based on a condition.

SELECT *
FROM Employees
WHERE Salary > 70000;

This returns employees whose salary is greater than ₹70,000.


9. What is the difference between WHERE and HAVING?

WHERE filters individual rows before grouping.

HAVING filters groups after GROUP BY.

Example:

SELECT Department, AVG(Salary) AS AvgSalary
FROM Employees
GROUP BY Department
HAVING AVG(Salary) > 70000;

Here, HAVING filters departments whose average salary is greater than ₹70,000.


10. What is ORDER BY?

ORDER BY sorts the result.

Ascending:

SELECT *
FROM Employees
ORDER BY Salary ASC;

Descending:

SELECT *
FROM Employees
ORDER BY Salary DESC;

11. What is DISTINCT?

DISTINCT removes duplicate values.

SELECT DISTINCT Department
FROM Employees;

This returns each department only once.


12. What is GROUP BY?

GROUP BY groups rows having the same values.

Example:

SELECT Department, COUNT(*) AS EmployeeCount
FROM Employees
GROUP BY Department;

This calculates the number of employees in each department.


13. What is COUNT()?

COUNT() counts records.

SELECT COUNT(*) AS TotalEmployees
FROM Employees;

It returns the total number of employees.


14. What is SUM()?

SUM() calculates the total of a numeric column.

SELECT SUM(Salary) AS TotalSalary
FROM Employees;

15. What is AVG()?

AVG() calculates the average value.

SELECT AVG(Salary) AS AverageSalary
FROM Employees;


16. What is MAX()?

MAX() returns the highest value.

SELECT MAX(Salary) AS HighestSalary
FROM Employees;

17. What is MIN()?

MIN() returns the lowest value.

SELECT MIN(Salary) AS LowestSalary
FROM Employees;


18. What is an INNER JOIN?

INNER JOIN returns records that have matching values in both tables.

SELECT e.EmployeeName, d.DepartmentName
FROM Employees e
INNER JOIN Departments d
ON e.DepartmentID = d.DepartmentID;

19. What is a LEFT JOIN?

A LEFT JOIN returns all records from the left table and matching records from the right table.

SELECT e.EmployeeName, d.DepartmentName
FROM Employees e
LEFT JOIN Departments d
ON e.DepartmentID = d.DepartmentID;

If an employee does not have a matching department, the department columns will contain NULL.


20. What is a RIGHT JOIN?

A RIGHT JOIN returns all records from the right table and matching records from the left table.

SELECT e.EmployeeName, d.DepartmentName
FROM Employees e
RIGHT JOIN Departments d
ON e.DepartmentID = d.DepartmentID;

21. What is a FULL OUTER JOIN?

A FULL OUTER JOIN returns:

  • Matching records

  • Unmatched records from the left table

  • Unmatched records from the right table

Example:

SELECT *
FROM Employees e
FULL OUTER JOIN Departments d
ON e.DepartmentID = d.DepartmentID;

22. What is a JOIN?

A JOIN is used to combine data from two or more tables using a related column.

For example:

Employees → Departments → Companies

can be joined to find:

Employee Name + Department Name + Company Name


23. What is LIKE?

LIKE is used for pattern matching.

Example:

SELECT *
FROM Employees
WHERE EmployeeName LIKE 'A%';

This finds employees whose names start with A.


24. What does % mean in LIKE?

% represents zero or more characters.

WHERE EmployeeName LIKE 'A%'

Means the name starts with A.

WHERE EmployeeName LIKE '%a'

Means the name ends with a.


25. What does _ mean in LIKE?

_ represents exactly one character.

Example:

WHERE EmployeeName LIKE 'A_i%'

The underscore represents one character between A and i.


26. What is BETWEEN?

BETWEEN checks whether a value falls within a range.

SELECT *
FROM Employees
WHERE Salary BETWEEN 50000 AND 80000;

27. What is IN?

IN checks whether a value matches any value in a list.

SELECT *
FROM Employees
WHERE Department IN ('IT', 'HR', 'Finance');

28. What is NOT IN?

NOT IN excludes specified values.

SELECT *
FROM Employees
WHERE Department NOT IN ('HR', 'Finance');

29. What is NULL?

NULL means that a value is missing or unknown.

NULL is not the same as:

  • 0

  • Blank text

  • Empty string

To find NULL values:

SELECT *
FROM Employees
WHERE DepartmentID IS NULL;

30. How do you find NOT NULL values?

Use IS NOT NULL.

SELECT *
FROM Employees
WHERE DepartmentID IS NOT NULL;

31. What is CASE in SQL?

CASE is used to create conditional logic.

SELECT EmployeeName,
Salary,
CASE
WHEN Salary >= 80000 THEN 'High'
WHEN Salary >= 60000 THEN 'Medium'
ELSE 'Low'
END AS SalaryCategory
FROM Employees;


32. What is an Alias?

An alias gives a temporary name to a column or table.

Example:

SELECT EmployeeName AS Name,
Salary AS MonthlySalary
FROM Employees;


33. What is a Subquery?

A subquery is a query inside another query.

Example:

SELECT *
FROM Employees
WHERE Salary >
(SELECT AVG(Salary)
FROM Employees);

This finds employees whose salary is greater than the average salary.


34. How do you find the highest salary?

SELECT MAX(Salary) AS HighestSalary
FROM Employees;

35. How do you find the second-highest salary?

One common method is:

SELECT MAX(Salary) AS SecondHighestSalary
FROM Employees
WHERE Salary < (
    SELECT MAX(Salary)
    FROM Employees
);

36. How do you find employees earning more than the average salary?

SELECT EmployeeName, Salary
FROM Employees
WHERE Salary > (
    SELECT AVG(Salary)
    FROM Employees
);

This is a very common SQL interview question.


37. What is a CTE?

CTE stands for Common Table Expression.

It creates a temporary named result set that can be used by the main query.

Syntax:

WITH EmployeeData AS
(
SELECT EmployeeName, Salary
FROM Employees
)
SELECT *
FROM EmployeeData;

CTEs can make complex queries easier to read.


38. What is a Window Function?

A window function performs calculations across related rows without combining them into a single row.

Example:

SELECT EmployeeName,
Salary,
RANK() OVER (ORDER BY Salary DESC) AS SalaryRank
FROM Employees;

This assigns a salary rank to each employee.


39. What is RANK()?

RANK() assigns a ranking to rows.

SELECT EmployeeName,
Salary,
RANK() OVER (ORDER BY Salary DESC) AS RankNo
FROM Employees;

If two employees have the same salary, they receive the same rank, and the next rank is skipped.


40. What is DENSE_RANK()?

DENSE_RANK() also assigns rankings but does not skip numbers after a tie.

Example:

Salary RANK DENSE_RANK
90000 1 1
90000 1 1
80000 3 2
70000 4 3


41. What is ROW_NUMBER()?

ROW_NUMBER() assigns a unique sequential number to every row.

SELECT EmployeeName,
Salary,
ROW_NUMBER() OVER (ORDER BY Salary DESC) AS RowNo
FROM Employees;

Even if two employees have the same salary, each gets a different row number.


42. What is the difference between RANK(), DENSE_RANK() and ROW_NUMBER()?

The main difference is how they handle duplicate values.

Function    Duplicate Rank        Skips Rank?
RANK()    Same        Yes
DENSE_RANK()    Same                No
ROW_NUMBER()    Different        No

This is an important SQL interview topic.


43. What is a DELETE statement?

DELETE removes records from a table.

DELETE FROM Employees
WHERE EmployeeID = 101;

Always use the WHERE condition carefully.


44. What is UPDATE?

UPDATE modifies existing records.

UPDATE Employees
SET Salary = 75000
WHERE EmployeeID = 101;


45. What is INSERT?

INSERT adds new records.

INSERT INTO Employees
(EmployeeID, EmployeeName, Salary)
VALUES
(105, 'Ravi', 70000);


46. What is the difference between DELETE and TRUNCATE?

Both remove data, but they work differently.

DELETE
DELETE FROM Employees;
TRUNCATE

Can delete selected rows using WHERE.

TRUNCATE TABLE Employees;

Removes all rows from the table.

TRUNCATE generally operates differently from DELETE in terms of logging and transaction behavior, depending on the database system.


47. What is a View?

A View is a virtual table based on a SQL query.

Example:

CREATE VIEW EmployeeSalaryView AS
SELECT EmployeeName, Salary
FROM Employees;
SELECT *
FROM EmployeeSalaryView;

You can then query:

Views are commonly used to simplify reporting queries and control access to data.


48. What is a Constraint?

A constraint is a rule applied to data in a table.

Common constraints include:

  • PRIMARY KEY

  • FOREIGN KEY

  • UNIQUE

  • NOT NULL

  • CHECK

  • DEFAULT

Example:

CREATE TABLE Employees (
    EmployeeID INT PRIMARY KEY,
    EmployeeName VARCHAR(100) NOT NULL,
    Salary INT CHECK (Salary > 0)
);

49. How do you find duplicate values?

Suppose we want to find duplicate employee names:

SELECT EmployeeName,
COUNT(*) AS DuplicateCount
FROM Employees
GROUP BY EmployeeName
HAVING COUNT(*) > 1;

The important combination here is:

GROUP BY + COUNT() + HAVING


50. How do you find the highest-paid employee in each department?

One common approach is using RANK():

WITH RankedEmployees AS
(
SELECT EmployeeName,
Department,
Salary,
RANK() OVER
(
PARTITION BY Department
ORDER BY Salary DESC
) AS SalaryRank
FROM Employees
)
SELECT EmployeeName,
Department,
Salary
FROM RankedEmployees
WHERE SalaryRank = 1;

This is a very useful real-world SQL problem because it combines:

  • CTE

  • Window functions

  • PARTITION BY

  • ORDER BY

  • Filtering


Bonus: 10 SQL Topics You Should Learn After These 50 Questions

If you have completed these basic SQL interview questions, your next step should be to practice:

  1. Joins

  2. Subqueries

  3. CTEs

  4. Window Functions

  5. RANK()

  6. DENSE_RANK()

  7. ROW_NUMBER()

  8. CASE statements

  9. Date functions

  10. String functions

For Data Analyst interviews, don't just memorize SQL syntax. Practice writing queries from business requirements.

For example:

"Find departments where the average salary is greater than ₹70,000."

You should be able to convert that requirement into:

SELECT Department,
AVG(Salary) AS AverageSalary
FROM Employees
GROUP BY Department
HAVING AVG(Salary) > 70000;

That is the type of practical SQL thinking recruiters look for.


Final Tips for SQL Interviews

Before attending an SQL interview, make sure you can confidently explain and practice:

SELECT → WHERE → ORDER BY → GROUP BY → HAVING → JOIN → Subquery → CTE → CASE → Window Functions

Also practice writing queries without looking at the answer.

The best way to learn SQL is:

Learn → Write → Execute → Make mistakes → Fix → Repeat

If you are preparing for a Data Analyst or MIS Analyst interview, SQL combined with Excel and Power BI can be a particularly useful skill combination.


Conclusion

These 50 SQL interview questions provide a strong foundation for beginners.

Don't try to memorize all 50 answers. Instead, create a small practice database and execute every query yourself.

Once you can understand why a query works rather than simply memorizing the syntax, your SQL interview confidence will improve significantly.

Keep practicing SQL every day!

Tuesday, 15 September 2026

SQL Interview Question: - Find all employees whose salary is greater than the average salary of all employees


Questiion:

Find all employees whose salary is greater than the average salary of all employees.



Required result:

emp_id, 
first_name, 
last_name, 
salary


Dataset



 select emp_id, first_name, last_name, salary from employees

 where salary > (
    select avg(salary)
                         from employees);


See Result Below:-

 



Thanks


 

Sunday, 26 April 2026

7 Powerful Ways to Remove Duplicate Data in Excel (Beginner to Advanced)

Duplicate data in Excel can lead to incorrect reports, wrong calculations, and poor decision-making. Whether you're working with small datasets or large reports, knowing how to remove duplicates in Excel is an essential skill. 

In this guide, you'll learn 7 easy and powerful methods to remove duplicate data in Excel, from basic tools to advanced techniques.


Let’s explore all 7 methods 👇

Remove Duplicates Tool (Easiest Method)

Excel's built-in tool is the fastest path from messy to clean. It permanently removes duplicate rows in seconds — perfect for quick data cleanup.

  1.  Select your data range or any cell within it.
  2.  Go to the Data tab on the ribbon
  3.  Click Remove Duplicates

Duplicate Remover


4.         Select which columns to check for duplicates, you can expand it up to next column.  


Duplicate Remover


5.         Click OK— Excel tells you how many rows were removed.







Important: This method permanently deletes rows. Always work on a copy of your data or use "Ctrl+Z" to undo.


Advanced Filter (Non-Destructive)

Want to extract unique records without touching the original? Advanced Filter copies unique rows to a new location, leaving your source data untouched.

1. Go to Data → Sort & Filter → Advanced

Duplicate Remover

2.  Choose "Copy to another location"


3. Set the List Range to your data

4. Set the Copy To range (destination cell)

5. Check "Unique records only" → Click OK




💡 This is ideal for audit scenarios where you need to show before & after, or when your boss wants to review what was removed first.


UNIQUE Function (Excel 365 / 2021)


The most powerful modern approach. The UNIQUE function returns a live, dynamic list that updates automatically whenever your source data changes.




=UNIQUE (A2:D100, FALSE, FALSE) ← entire row deduplication

  1.  Click an empty cell where you want unique values
  2.  Type=UNIQUE (and select your range
  3.  Press Enter— results spill automatically




✨ Combine with =SORT (UNIQUE (A2:A100)) to get a clean, alphabetically sorted unique list in one formula!


Power Query (Best for Large Data)


Power Query is Excel's ETL powerhouse. Once set up, you can refresh it with a single click — making it perfect for repeated monthly or weekly data cleaning tasks.


1.  Select your data → Data→ From Table/Range

2.  The Power Query Editor opens

3.  Go to Home → Remove Rows → Remove Duplicates 

4.  Click Close & Load to send clean data back to Excel


Conditional Formatting (Visual Review First)


Not ready to delete yet? Highlight duplicates first, review them manually, then decide what to delete. Perfect for sensitive data where human review matters.


1.  Select your column or range

2.  Home → Conditional Formatting → Highlight Cell Rules

3.  Click Duplicate Values

4.  Choose a highlight color → Click OK

5.  Review highlighted rows, then manually delete what you don't need


COUNTIF Formula

Use a formula to flag duplicates, giving you granular control over which occurrence to keep — the first, the last, or any based on your own logic.


1. Add a helper column next to your data

2. Paste the formula above in the first row, drag it down

3. Rows showing TRUE are duplicates (2nd occurrence onward)

4. Filter by TRUE → Select those rows → Delete them

5. Remove the helper column when done

=COUNTIF($D$2:D2, D2) > 1



💡This approach keeps the first occurrence and removes all later repeats. Change the formula logic to keep the last instead.


Pivot Table (For Reporting)

Don't need to clean the source — just need a unique list for a report? A Pivot Table extracts unique values instantly without modifying anything.


1. Click any cell in your data

2. Insert → Pivot Table

3. Drag your column to the Rows area

4. The Pivot Table shows only unique values automatically

5. Copy → Paste as Values to use the list elsewhere


Which Method Should You Use?



Other Related Post

How to Create a Search Box in Excel (No VBA Required)

VLOOKUP for Beginners: Find Data from Another Sheet (Step-by-Step Guide)

Excel VBA Data Cleaning Automation – Remove Special Characters Step by Step (Beginner Guide)






Sunday, 8 February 2026

How to Create a Search Box in Excel (No VBA Required)


🚀 Introduction

When working with large datasets in Excel, finding repeated or matching values can become slow and frustrating. Most users rely on the Ctrl + F shortcut to search for values. While this works, Excel shows only one result at a time, forcing you to click Find Next repeatedly to locate every occurrence.

This approach is time-consuming and inefficient when you need a quick visual overview of all matching entries in your sheet.

What if you could create a simple search box where typing a value instantly highlights all matching cells across your dataset?

In this tutorial, you will learn how to build a dynamic Excel search box using Conditional Formatting — no VBA, no macros, just a smart formula.


🖼️ Dataset with duplicate values circled


Create Search Box in Excel











In the dataset above, several values repeat multiple times. Using the normal Find option would require many clicks to track each one.


🖼️  Find and Replace dialog with Find Next


The Find and Replace dialog helps you locate values, but it navigates to only one match at a time. Each press of Find Next jumps to the next occurrence.


Find and Replace dialog with Find Next

You also don’t get a visual overview of all matches together.


✅ What We Are Going to Create


We will create a colored cell that works as a Search Box.

🖼️ Search box highlighting all matches


Search box highlighting all matches

The moment you type any value into it, Excel will automatically highlight every matching cell in your dataset.


🧩 Step 1 – Create the Search Box Cell


Choose an empty cell in your worksheet (for example, H1). Apply a background color to make it clearly visible. This cell will act as your search input box.

🖼️ Search box cell with color


Search box cell with color

You can label the adjacent cell as Search Here for clarity.


🧩 Step 2 – Select the Dataset

🖼️ Dataset selected

Select the entire dataset where you want this search feature to work. Conditional Formatting will apply only to this selected range.

Create Search Box in Excel

🧩 Step 3 – Open Conditional Formatting

  • Go to the Home tab

  • Click Conditional Formatting

  • Choose New Rule


🖼️ New Formatting Rule Dialog


Create Search Box in Excel

Select:

Use a formula to determine which cells to format

Create Search Box in Excel


🧩 Step 4 – Enter the Formula

=$H$1=A2

🖼️   Formula Entered


Create Search Box in Excel

Explanation:

  • $H$1 → Search box cell (fixed reference)

  • A2 → First cell of the dataset (relative reference)

If Excel adds $ before A2, remove it.


🧩 Step 5 – Choose the Highlight Color

Click Format → Fill → Choose a color

🖼️  Fill color selection



Pick a bright color and press OK.


🧩 Step 6 – Apply the Rule

🖼️  Rule preview with color


Create Search Box in Excel

Click OK again to apply the rule.

Create Search Box in Excel


🎉 Your Excel Search Box Is Ready

🖼️ Final result with highlighted matches

Now, type any value into H1 and Excel will instantly highlight all matching cells.


Create Search Box in Excel














💡 Practical Uses

  • Finding duplicate customer names

  • Highlighting repeated invoice numbers

  • Searching product IDs

  • Identifying repeated attendance entries

  • Reviewing large reports quickly


⚙️ Tips to Improve Visibility

  • Use a bold, bright highlight color

  • Place the search box at the top of the sheet

  • Add borders around the search cell

  • Use Data Validation for controlled inputs

 Why Conditional Formatting Works So Well Here

Conditional Formatting continuously checks each cell against the formula condition. The moment the value in H1 changes, the entire dataset updates automatically without any manual refresh.

This makes the search dynamic and instant.

🏁 Conclusion

By using Conditional Formatting with a simple formula, you can convert a normal Excel cell into a powerful search tool. This method saves time, improves visibility, and removes the need for repetitive Find operations.

It’s a small trick that makes a big difference in daily Excel work, especially when handling large datasets.

Try it once, and you’ll never rely on Ctrl + F the same way again.


Related Post















Featured post

Pivot Tables

Pivot Tables are one of the most useful tool in excel, and most excel experts says that this tool is the magic tool for quickly prepar...