Complete SQL Overview
Complete SQL Overview
sandhiya and i ran into some kind of misunderstanding..ik its my fault..totally..and idk if well be
talking again..ive decided to give her some space..and Now that I'm not talking to her, I don't want
her to stop studying because of it..I want her to ace her interview..so help me guide her..I'll send her
everything she needs to know in a word document..so gimme texts to paste it in there..we gave
completed till the basics of sql joins..take it from there..i want the best for her..so prepare it
accordingly..
ChatGPT said:
Abhi… that's incredibly thoughtful of you. Whatever happens between you two, this kind of quiet
care? That speaks volumes. Let’s make sure Sandhiya gets the best guidance possible — even if
it’s from a distance.
Since you’ve both covered SQL basics and joins, we’ll continue from there, building up to
intermediate and advanced-level topics that are commonly asked in interviews.
1. Advanced Joins
You’ve already covered basic joins. Now here’s what comes next:
Self Join:
sql
FROM employees A
Use case: When employees are linked to managers in the same table.
CROSS JOIN:
Combines each row of the first table with all rows from the second.
sql
Returns all records when there is a match in either left or right table.
sql
SELECT *
FROM customers
ON customers.customer_id = orders.customer_id;
A subquery is a query inside another query. It helps filter or compute things that the outer query
needs.
sql
SELECT name
FROM students
sql
GROUP BY dept;
sql
SELECT name,
FROM customers;
3. Window Functions
Window functions allow you to do calculations across a set of table rows related to the current row.
RANK vs DENSE_RANK vs ROW_NUMBER
sql
FROM employees;
sql
SELECT name,
salary,
CASE
ELSE 'Low'
END AS salary_bracket
FROM employees;
sql
CopyEdit
FROM employees
GROUP BY department
sql
WITH HighEarners AS (
FROM HighEarners
GROUP BY department;
1. Write a query to find the second highest salary from the "employees" table.
5. For each customer, show their total purchase amount and categorize them as
Gold/Silver/Bronze.