1. Finding the N-th Highest Salary
This is the single most frequently asked query in fresher database interviews.
sql
2. Finding & Removing Duplicate Records
sql
3. SQL Joins & Employee-Manager Hierarchy (Self Join)
sql
Visual Summary of SQL Joins:
- INNER JOIN: Returns records that have matching values in both tables.
- LEFT (OUTER) JOIN: Returns all records from the left table, and the matched records from the right table.
- RIGHT (OUTER) JOIN: Returns all records from the right table, and matched records from the left table.
- FULL OUTER JOIN: Returns all records when there is a match in either left or right table.
4. Essential Window Functions (ROW_NUMBER, RANK, DENSE_RANK)
sql
ROW_NUMBER(): Assigns a unique sequential integer to each row within a partition without duplicates (1, 2, 3, 4).RANK(): Assigns rank with gaps on tied values (1, 2, 2, 4).DENSE_RANK(): Assigns rank without gaps on tied values (1, 2, 2, 3).
5. ACID Properties and Indexing Optimization
- Atomicity: All operations in a database transaction succeed or all rollback.
- Consistency: Database transitions from one valid state to another valid state.
- Isolation: Concurrent transactions execute without dirty reads or race conditions.
- Durability: Committed data is safely written to disk and survives system crashes.
sql