ProjectWithSourceCodes
1.04K subscribers
276 photos
8 videos
43 files
1.31K links
Free Source Code Projects for Students 🚀 | Python | Java | Android | Web Dev | AI/ML | Final Year Projects | BCA • BTech • MCA | Interview Prep | Job Alerts

Website: https://updategadh.com
Download Telegram
SQL CHEAT SHEET — Save This Post!
Most Asked Queries in Tech Interviews!

====================================

SQL is asked in 90% of tech interviews —
TCS, Infosys, Amazon, even AI roles need it!
Master these queries TODAY!

====================================
BASIC QUERIES

SELECT * FROM employees;
-> Get all data from table

SELECT name, salary FROM employees
WHERE salary > 50000;
-> Filter rows with condition

SELECT * FROM employees
ORDER BY salary DESC LIMIT 5;
-> Top 5 highest paid employees

====================================
AGGREGATE FUNCTIONS

SELECT COUNT(*) FROM employees;
-> Total number of rows

SELECT AVG(salary) FROM employees;
-> Average salary

SELECT department, COUNT(*) FROM employees
GROUP BY department;
-> Count employees per department

SELECT department, AVG(salary) FROM employees
GROUP BY department
HAVING AVG(salary) > 60000;
-> Departments with avg salary > 60k

====================================
JOINS — Most Asked in Interviews!

INNER JOIN -> Only matching rows in both tables
SELECT e.name, d.dept_name
FROM employees e
INNER JOIN departments d
ON e.dept_id = d.id;

LEFT JOIN -> All rows from left + matching right
SELECT e.name, d.dept_name
FROM employees e
LEFT JOIN departments d
ON e.dept_id = d.id;

SELF JOIN -> Table joined with itself
SELECT e1.name, e2.name AS manager
FROM employees e1
JOIN employees e2
ON e1.manager_id = e2.id;

====================================
SUBQUERIES — Asked in Advanced Rounds!

Find employees earning more than average:
SELECT name FROM employees
WHERE salary > (
SELECT AVG(salary) FROM employees
);

Find 2nd highest salary (Classic Question!):
SELECT MAX(salary) FROM employees
WHERE salary < (
SELECT MAX(salary) FROM employees
);

====================================
WINDOW FUNCTIONS — Modern SQL!

Rank employees by salary:
SELECT name, salary,
RANK() OVER (ORDER BY salary DESC) as rnk
FROM employees;

Running total of salaries:
SELECT name, salary,
SUM(salary) OVER (ORDER BY id) as running_total
FROM employees;

====================================
MUST-KNOW CONCEPTS:

Primary Key -> Unique identifier for each row
Foreign Key -> Links 2 tables together
Index -> Speeds up search queries
Normalization -> Reduce data redundancy
Transaction -> ACID properties (all or nothing)

====================================
TOP 5 SQL INTERVIEW QUESTIONS:

1. Find duplicate records in a table
2. Find employees with no manager
3. Find departments with zero employees
4. Find Nth highest salary
5. Find employees who joined this month

Practice these on a free SQL site!

====================================
PRACTICE FREE ON:
SQLZoo.net
HackerRank SQL section
LeetCode Database problems

====================================
Save this post before your next interview!
Get FREE projects too:
https://t.me/Projectwithsourcecodes

Share with your placement batch!

#SQLCheatSheet #SQL #DatabaseInterview #MySQL
#PostgreSQL #JoinsInSQL #Subqueries #WindowFunctions
#BTech2026 #MCA2026 #BCA2026 #PlacementPrep
#TechInterview #DataAnalyst #BackendDeveloper
#ProjectWithSourceCodes #StudentsOfIndia #LearnSQL
SQL CHEAT SHEET - Save This!
Most Asked SQL in Tech Interviews!

====================================

SQL is tested in 90% of tech interviews!
TCS, Infosys, Amazon, Flipkart, Data Analyst
roles ALL require strong SQL. Master this!

====================================
BASIC QUERIES

SELECT * FROM employees;
-> Get all rows from table

SELECT name, salary FROM employees
WHERE salary > 50000;
-> Filter rows with condition

SELECT * FROM employees
ORDER BY salary DESC LIMIT 5;
-> Top 5 highest paid employees

SELECT DISTINCT department FROM employees;
-> Get unique departments only

====================================
AGGREGATE FUNCTIONS

SELECT COUNT(*) FROM employees;
-> Total number of rows

SELECT AVG(salary) FROM employees;
-> Average salary

SELECT MAX(salary), MIN(salary) FROM employees;
-> Highest and lowest salary

SELECT department, COUNT(*) as emp_count
FROM employees
GROUP BY department
HAVING COUNT(*) > 5;
-> Departments with more than 5 employees

====================================
JOINS - Most Asked in Interviews!

INNER JOIN - Only matching rows in both tables:
SELECT e.name, d.dept_name
FROM employees e
INNER JOIN departments d ON e.dept_id = d.id;

LEFT JOIN - All from left + matching right:
SELECT e.name, d.dept_name
FROM employees e
LEFT JOIN departments d ON e.dept_id = d.id;

SELF JOIN - Table joined with itself:
SELECT e1.name, e2.name AS manager
FROM employees e1
JOIN employees e2 ON e1.manager_id = e2.id;

====================================
SUBQUERIES - Asked in Advanced Rounds!

Employees earning more than average:
SELECT name FROM employees
WHERE salary > (SELECT AVG(salary) FROM employees);

2nd highest salary (Classic Question!):
SELECT MAX(salary) FROM employees
WHERE salary < (SELECT MAX(salary) FROM employees);

Nth highest salary using LIMIT:
SELECT salary FROM employees
ORDER BY salary DESC LIMIT 1 OFFSET N-1;

====================================
WINDOW FUNCTIONS - Modern SQL!

Rank employees by salary:
SELECT name, salary,
RANK() OVER (ORDER BY salary DESC) as rnk
FROM employees;

Row number within each department:
SELECT name, department,
ROW_NUMBER() OVER
(PARTITION BY department ORDER BY salary DESC)
FROM employees;

====================================
TOP 5 SQL INTERVIEW QUESTIONS:

1. Find duplicate records in a table
2. Find employees with no manager (NULL)
3. Find departments with zero employees
4. Find Nth highest salary
5. Difference between WHERE and HAVING?

====================================
PRACTICE FREE ON:
SQLZoo -> sqlzoo.net
HackerRank -> hackerrank.com/domains/sql
LeetCode -> leetcode.com/problemset/database

====================================
Save this before your next interview!
Get FREE projects with database code:
https://t.me/Projectwithsourcecodes

Share with your placement batch!

#SQLCheatSheet #SQL #MySQL #PostgreSQL
#DatabaseInterview #Joins #Subqueries #WindowFunctions
#BTech2026 #MCA2026 #BCA2026 #PlacementPrep
#DataAnalyst #BackendDeveloper #TechInterview
#ProjectWithSourceCodes #StudentsOfIndia