SQL_Interview_Questions
SQL_Interview_Questions
SQL (Structured Query Language) is used to manage and manipulate databases. It is important in
data analytics as it allows data extraction, transformation, and analysis efficiently.
2. Difference between INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL OUTER JOIN
WHERE filters rows before grouping, while HAVING filters groups after aggregation.
Example:
SELECT department, COUNT(*) AS num_employees FROM employees
GROUP BY department HAVING COUNT(*) > 5;
Use DISTINCT:
SELECT DISTINCT column_name FROM table_name;
Intermediate SQL:
SELECT DISTINCT salary FROM employees ORDER BY salary DESC LIMIT 1 OFFSET 1;
Advanced SQL:
- Use indexes.
- Avoid SELECT *.
- Optimize joins and subqueries.
- Use EXPLAIN PLAN.
2. Views in SQL
Example:
SELECT name, department, salary, RANK() OVER (PARTITION BY department ORDER BY salary
DESC) AS rank FROM employees;