SQL Interview Questions and Answers for Infor / BI / Analytics Roles
1. Basics of SQL
Q1. What is SQL and what are its types? A: SQL (Structured Query Language) is used to manage and
manipulate relational databases. Types: - DDL (Data Definition Language): CREATE, ALTER, DROP - DML
(Data Manipulation Language): SELECT, INSERT, UPDATE, DELETE - DCL (Data Control Language): GRANT,
REVOKE - TCL (Transaction Control Language): COMMIT, ROLLBACK, SAVEPOINT
Q2. Difference between WHERE and HAVING clauses A: - WHERE filters rows before aggregation. -
HAVING filters rows after aggregation.
Q3. Difference between INNER JOIN, LEFT JOIN, RIGHT JOIN, FULL OUTER JOIN A: - INNER JOIN: returns
rows matching in both tables - LEFT JOIN: all rows from left table + matching from right - RIGHT JOIN: all
rows from right table + matching from left - FULL OUTER JOIN: all rows from both tables, NULL if no match
2. Queries
Q4. Fetch top 5 highest salaries from Employee table
SELECT * FROM Employee
ORDER BY Salary DESC
LIMIT 5; -- For SQL Server use TOP 5
Q5. Find second highest salary
SELECT MAX(Salary) FROM Employee
WHERE Salary < (SELECT MAX(Salary) FROM Employee);
Q6. Retrieve employees who joined in last 6 months
SELECT * FROM Employee
WHERE JoiningDate >= DATEADD(MONTH, -6, GETDATE());
3. Aggregations and Grouping
Q7. Count employees in each department
1
SELECT DepartmentID, COUNT(*) AS EmployeeCount
FROM Employee
GROUP BY DepartmentID;
Q8. Average salary per department > 50000
SELECT DepartmentID, AVG(Salary) AS AvgSalary
FROM Employee
GROUP BY DepartmentID
HAVING AVG(Salary) > 50000;
4. Subqueries
Q9. Difference between correlated and non-correlated subquery A: - Non-correlated: runs once
independently. - Correlated: runs for each row of outer query.
Q10. Employees with salary above dept average
SELECT * FROM Employee e
WHERE Salary > (
SELECT AVG(Salary) FROM Employee
WHERE DepartmentID = [Link]
);
Q11. Employees in same department as 'John'
SELECT * FROM Employee
WHERE DepartmentID = (
SELECT DepartmentID FROM Employee WHERE Name = 'John'
);
5. Advanced SQL
Q12. CTE for cumulative salary per department
WITH DeptSalary AS (
SELECT DepartmentID, Name, Salary,
SUM(Salary) OVER (PARTITION BY DepartmentID ORDER BY Name) AS
2
CumulativeSalary
FROM Employee
)
SELECT * FROM DeptSalary;
Q13. Window functions example
SELECT Name, DepartmentID, Salary,
ROW_NUMBER() OVER (PARTITION BY DepartmentID ORDER BY Salary DESC) AS
RankInDept
FROM Employee;
Q14. Explain indexing A: Indexes improve search performance by allowing faster row retrieval, especially
for large tables. Types: clustered, non-clustered.
6. Data Manipulation
Q15. Difference between DELETE and TRUNCATE - DELETE: removes rows, can use WHERE, logs each row,
can be rolled back - TRUNCATE: removes all rows, faster, cannot use WHERE, minimally logged
Q16. Update salary by 10%
UPDATE Employee
SET Salary = Salary * 1.1
WHERE DepartmentID = 3;
Q17. Insert multiple rows
INSERT INTO Employee (Name, DepartmentID, Salary)
VALUES ('Alice',1,50000), ('Bob',2,60000), ('Charlie',1,55000);
7. Infor / Birst / ETL Scenarios
Q18. Connect SQL to dashboards - Use Birst or Infor Analytics connector to fetch SQL results into
dashboards.
Q19. SQL optimization for large datasets - Use indexes, avoid SELECT *, use CTEs, filter early, avoid nested
subqueries if possible.
3
Q20. Handling SCD using SQL - Implement Type 1 (overwrite) or Type 2 (historical rows with effective
dates) logic in SQL.
Q21. Difference between staging and warehouse tables - Staging: temporary raw data for
transformation - Warehouse: cleaned, structured, historical data for reporting
8. Scenario-Based Questions
Q22. Find duplicates
SELECT Name, COUNT(*)
FROM Employee
GROUP BY Name
HAVING COUNT(*) > 1;
Q23. Employees without projects
SELECT * FROM Employee e
WHERE NOT EXISTS (
SELECT 1 FROM ProjectAssignments p
WHERE [Link] = [Link]
);
Q24. Aggregate sales monthly and quarterly
SELECT YEAR(SaleDate) AS Yr, MONTH(SaleDate) AS Mth, SUM(Amount) AS MonthlySales
FROM Sales
GROUP BY YEAR(SaleDate), MONTH(SaleDate);
SELECT YEAR(SaleDate) AS Yr, DATEPART(QUARTER, SaleDate) AS Qtr, SUM(Amount) AS
QuarterlySales
FROM Sales
GROUP BY YEAR(SaleDate), DATEPART(QUARTER, SaleDate);
Prepared for Infor BI / Analytics SQL Interviews.