1๏ธโฃ What is a CTE (Common Table Expression)?
A temporary result set used for complex queries.
WITH temp AS (SELECT * FROM employees WHERE salary > 50000)
SELECT * FROM temp;
2๏ธโฃ Difference between RANK(), DENSE_RANK(), and ROW_NUMBER()?
โฆ
ROW_NUMBER(): Unique sequence numberโฆ
RANK(): Skips ranks for tiesโฆ
DENSE_RANK(): No gaps in ranking3๏ธโฃ What is a window function?
Calculations across a set of rows related to the current row, using
OVER(PARTITION BYโฆ).4๏ธโฃ Difference between WHERE and HAVING?
โฆ
WHERE: Filters rows before aggregationโฆ
HAVING: Filters rows after aggregation5๏ธโฃ What is indexing and how does it work?
Speeds up queries by creating fast-lookups, like a bookโs index.
6๏ธโฃ How to remove duplicate records in SQL?
SELECT DISTINCT * FROM table_name;
7๏ธโฃ Difference between UNION and UNION ALL?
โฆ
UNION: Removes duplicatesโฆ
UNION ALL: Includes all rows8๏ธโฃ How to update data using JOIN?
UPDATE emp
SET emp.salary = dept.bonus
FROM emp
JOIN dept ON emp.dept_id = dept.id;
9๏ธโฃ Explain COALESCE() vs ISNULL().
โฆ
COALESCE(): Returns first non-null from a listโฆ
ISNULL(): Replaces NULL with a specified value (SQL Server)๐ What is a correlated subquery?
A subquery referencing outer query columns, executed row-by-row.
๐ฌ Tap โค๏ธ for more!