SQL Tutorials

 

SQL Tutorials, Scripts & Best Practices

This page contains practical SQL content useful for interviews, real-time projects, ETL development, and query tuning. I have included scripts, examples, and explanations that help beginners and experienced developers.


🔹 1. SQL Basics

  • SELECT, INSERT, UPDATE, DELETE

  • WHERE, GROUP BY, HAVING

  • ORDER BY, DISTINCT

  • Joins (Inner, Left, Right, Full, Cross)

Example:

SELECT emp_id, emp_name, salary FROM employees WHERE salary > 50000;

🔹 2. Advanced SQL

  • Window Functions (ROW_NUMBER, RANK, LEAD/LAG)

  • Subqueries & CTEs

  • Pivoting & Unpivoting

  • Merge statement

  • Analytic functions for ETL use cases

Example:

SELECT emp_id, salary, ROW_NUMBER() OVER (ORDER BY salary DESC) AS rn FROM employees;

🔹 3. SQL Performance Tuning

  • Understanding Indexes

  • How to read Execution Plans

  • Remove unnecessary DISTINCT

  • Use EXISTS instead of IN for large datasets

  • Avoid functions on indexed columns

  • Correct join order

Example (find high-cost operations):

Check for:Table scansKey lookupsSorts, Hash joinsMissing index suggestions

🔹 4. SQL Interview Questions

  • Difference between ROW_NUMBER, RANK, DENSE_RANK

  • What is a clustered vs non-clustered index

  • How to identify a slow query

  • What is normalization

  • What is a correlated subquery


🔹 5. SQL Practice Problems

  • Find the 2nd highest salary

  • Get duplicate records

  • Remove duplicates

  • Find employees who joined in last 90 days

  • Identify customers without orders


No comments:

Post a Comment

Most Recent posts

How to configure DB Connector Stages –