SQL Programming Resources
75.5K subscribers
516 photos
13 files
472 links
Find top SQL resources from global universities, cool projects, and learning materials for data analytics.

Admin: @coderfun

Useful links: heylink.me/DataAnalytics

Promotions: @love_data
Download Telegram
SQL Interview Questions with Answers Part-1: ☑️

1. What is SQL? 
   SQL (Structured Query Language) is a standardized programming language designed to manage and manipulate relational databases. It allows you to query, insert, update, and delete data, as well as create and modify schema objects like tables and views.

2. Differentiate between SQL and NoSQL databases. 
   SQL databases are relational, table-based, and use structured query language with fixed schemas, ideal for complex queries and transactions. NoSQL databases are non-relational, can be document, key-value, graph, or column-oriented, and are schema-flexible, designed for scalability and handling unstructured data.

3. What are the different types of SQL commands?
⦁ DDL (Data Definition Language): CREATE, ALTER, DROP (define and modify structure)
⦁ DML (Data Manipulation Language): SELECT, INSERT, UPDATE, DELETE (data operations)
⦁ DCL (Data Control Language): GRANT, REVOKE (permission control)
⦁ TCL (Transaction Control Language): COMMIT, ROLLBACK, SAVEPOINT (transaction management)

4. Explain the difference between WHERE and HAVING clauses.
WHERE filters rows before grouping (used with SELECT, UPDATE).
HAVING filters groups after aggregation (used with GROUP BY), e.g., filtering aggregated results like sums or counts.

5. Write a SQL query to find the second highest salary in a table. 
   Using a subquery:
SELECT MAX(salary) FROM employees  
WHERE salary < (SELECT MAX(salary) FROM employees);

Or using DENSE_RANK():
SELECT salary FROM (  
  SELECT salary, DENSE_RANK() OVER (ORDER BY salary DESC) as rnk 
  FROM employees) t 
WHERE rnk = 2;


6. What is a JOIN? Explain different types of JOINs. 
   A JOIN combines rows from two or more tables based on a related column:
⦁ INNER JOIN: returns matching rows from both tables.
⦁ LEFT JOIN (LEFT OUTER JOIN): all rows from the left table, matched rows from right.
⦁ RIGHT JOIN (RIGHT OUTER JOIN): all rows from right table, matched rows from left.
⦁ FULL JOIN (FULL OUTER JOIN): all rows when there’s a match in either table.
⦁ CROSS JOIN: Cartesian product of both tables.

7. How do you optimize slow-performing SQL queries?
⦁ Use indexes appropriately to speed up lookups.
⦁ Avoid SELECT *; only select necessary columns.
⦁ Use joins carefully; filter early with WHERE clauses.
⦁ Analyze execution plans to identify bottlenecks.
⦁ Avoid unnecessary subqueries; use EXISTS or JOINs.
⦁ Limit result sets with pagination if dealing with large datasets.

8. What is a primary key? What is a foreign key?
⦁ Primary Key: A unique identifier for records in a table; it cannot be NULL.
⦁ Foreign Key: A field that creates a link between two tables by referring to the primary key in another table, enforcing referential integrity.

9. What are indexes? Explain clustered and non-clustered indexes.
⦁ Indexes speed up data retrieval by providing quick lookups.
⦁ Clustered Index: Sorts and stores the actual data rows in the table based on the key; a table can have only one clustered index.
⦁ Non-Clustered Index: Creates a separate structure that points to the data rows; tables can have multiple non-clustered indexes.

10. Write a SQL query to fetch the top 5 records from a table. 
    In SQL Server and PostgreSQL:
SELECT * FROM table_name  
ORDER BY some_column DESC 
LIMIT 5; 

In SQL Server (older syntax):
SELECT TOP 5 * FROM table_name  
ORDER BY some_column DESC; 


React ♥️ for Part 2
14
𝗔𝗜 𝗮𝗻𝗱 𝗠𝗟 𝗣𝗿𝗼𝗴𝗿𝗮𝗺 𝗯𝘆 𝗖𝗖𝗘, 𝗜𝗜𝗧 𝗠𝗮𝗻𝗱𝗶😍

Freshers get 15 LPA Average Salary with AI & ML Skills!

💻 100% Online
6 Months Duration
👨‍🏫 Learn from IIT Professors
📌 Open for Students ,Freshers & Working Professionals

💼 Placement Assistance with 5000+ Companies
📈 High Demand Skills for Future Tech Jobs

Top companies are hiring for candidates with 𝗔𝗜, 𝗠𝗮𝗰𝗵𝗶𝗻𝗲 𝗟𝗲𝗮𝗿𝗻𝗶𝗻𝗴 skills in 2026

🔥Deadline :- 17th May

  𝗔𝗽𝗽𝗹𝘆 𝗡𝗼𝘄👇 :- 

https://pdlink.in/4nmI024
.
Get Placement Assistance With 5000+ Companies
1
Stored Procedures 💯

🧠 1. What is a Stored Procedure?
A Stored Procedure is a saved SQL program
• Stored inside the database
• Can be executed anytime

Think like this 👇
“Reusable SQL code block”

2. Why Use Stored Procedures?
• Reuse SQL logic
• Reduce repeated code
• Better security
• Faster execution for repeated tasks

3. Basic Syntax

👉 MySQL Example:
DELIMITER //

CREATE PROCEDURE GetEmployees()
BEGIN
SELECT * FROM employees;
END //

DELIMITER ;

▶️ 4. Execute Stored Procedure
CALL GetEmployees();

🔥 5. Procedure with Parameter
DELIMITER //

CREATE PROCEDURE GetDeptEmployees(IN dept_name VARCHAR(50))
BEGIN
SELECT * FROM employees
WHERE department = dept_name;
END //

DELIMITER ;

▶️ 6. Execute Parameterized Procedure
CALL GetDeptEmployees('IT');

7. Drop Stored Procedure
DROP PROCEDURE GetEmployees;

🎯 8. Real Example
Increase salary for all IT employees:

DELIMITER //

CREATE PROCEDURE IncreaseSalary()
BEGIN
UPDATE employees
SET salary = salary + 5000
WHERE department = 'IT';
END //

DELIMITER ;

🎯 9. Practice Tasks
1. Create procedure to show all employees
2. Create procedure for HR employees
3. Create procedure with salary parameter
4. Execute stored procedure
5. Drop procedure

Mini Challenge 🔥

Create procedure to return employees with salary > given value

Solution

DELIMITER //

CREATE PROCEDURE GetHighSalaryEmployees(IN min_salary INT)
BEGIN
SELECT *
FROM employees
WHERE salary > min_salary;
END //

DELIMITER ;

▶️ Execute Procedure

CALL GetHighSalaryEmployees(50000);

Returns employees earning more than 50k

Key Difference:
Function → returns value
Procedure → performs action / multiple operations

Double Tap ❤️ For More
3
🚀 𝗕𝗲𝗰𝗼𝗺𝗲 𝗝𝗼𝗯-𝗥𝗲𝗮𝗱𝘆 𝗶𝗻 𝗗𝗮𝘁𝗮 𝗦𝗰𝗶𝗲𝗻𝗰𝗲 & 𝗔𝗜 𝘄𝗶𝘁𝗵 𝗜𝗻𝗱𝘂𝘀𝘁𝗿𝘆 𝗘𝘅𝗽𝗲𝗿𝘁𝘀! 📊

Learn the most in-demand skills of 2026

💫Data Science ,AI,ML &Python & SQL

💼 Get Placement Assistance
🎓 Beginner Friendly Program
💻 Learn Online from Anywhere
📈 Build Skills Companies Actually Hire For

🔥 AI is changing every industry — this is the best time to upskill and secure high-paying tech jobs.

𝐑𝐞𝐠𝐢𝐬𝐭𝐞𝐫 𝐍𝐨𝐰 👇:-

 https://pdlink.in/4fdWxJB

Limited Seats Available – Apply Fast!
1
Which command is used to execute a stored procedure in MySQL?
Anonymous Quiz
54%
A. EXECUTE
20%
B. RUN
22%
C. CALL
4%
D. START
Which keyword is used to pass input parameter in MySQL procedure?
Anonymous Quiz
4%
A. OUT
38%
B. INPUT
28%
C. PARAM
31%
D. IN
𝗣𝗿𝗼𝗱𝘂𝗰𝘁 𝗠𝗮𝗻𝗮𝗴𝗲𝗺𝗲𝗻𝘁 𝘄𝗶𝘁𝗵 𝗔𝗜 𝗣𝗿𝗼𝗴𝗿𝗮𝗺 by iHUB IIT Roorkee 😍

Freshers get paid 12 LPA average salary for the role of Associate Product Manager! 💼

𝗛𝗶𝗴𝗵𝗹𝗶𝗴𝗵𝘁𝘀:
Learn from IIT Roorkee Professors
Placement support from 5,000+ companies
Professional Certification in Product Management with Applied AI
100% Online Program
Open to Everyone

📅𝗗𝗲𝗮𝗱𝗹𝗶𝗻𝗲: 17th May 2026

  𝗔𝗽𝗽𝗹𝘆 𝗡𝗼𝘄👇 :- 

https://pdlink.in/4ddJZ5C

Limited Seats Available — Apply Soon!
🔥 Now, let’s move to the next topic:

Triggers in SQL
(Automation inside database 💯)

🧠 1. What is a Trigger?
A Trigger is a special SQL block
👉 that runs automatically
👉 when an event happens in a table

Think like this 👇
👉 “Automatic action on INSERT / UPDATE / DELETE”

2. Why Use Triggers?
Automatic logging
Data validation
Audit tracking
Prevent invalid operations

3. Types of Triggers
BEFORE INSERT → Runs before inserting data
AFTER INSERT → Runs after inserting data
BEFORE UPDATE → Runs before updating
AFTER UPDATE → Runs after updating
BEFORE DELETE → Runs before deleting
AFTER DELETE → Runs after deleting

🔥 4. Basic Trigger Example
👉 Automatically log inserted employee

CREATE TABLE employee_log (
log_message VARCHAR(255)
);

DELIMITER //

CREATE TRIGGER after_employee_insert
AFTER INSERT ON employees
FOR EACH ROW
BEGIN
INSERT INTO employee_log
VALUES (CONCAT('New employee added: ', NEW.name));
END //

DELIMITER ;

🧠 5. Important Keywords
NEW → New inserted/updated value
OLD → Previous value before update/delete

6. BEFORE UPDATE Example
👉 Prevent negative salary
DELIMITER //

CREATE TRIGGER check_salary
BEFORE UPDATE ON employees
FOR EACH ROW
BEGIN
IF NEW.salary < 0 THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'Salary cannot be negative';
END IF;
END //

DELIMITER ;

7. Drop Trigger
DROP TRIGGER after_employee_insert;

🎯 8. Practice Tasks
1. Create AFTER INSERT trigger
2. Create BEFORE UPDATE trigger
3. Prevent negative salary using trigger
4. Log deleted employees
5. Drop created trigger

Mini Challenge 🔥
👉 Create trigger to automatically save deleted employee names into another table

🔥 Mini Challenge Solution

👉 Automatically save deleted employee names into another table

Step 1: Create Log Table

CREATE TABLE deleted_employees (
emp_id INT,
name VARCHAR(50),
deleted_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

Step 2: Create Trigger

DELIMITER //

CREATE TRIGGER log_deleted_employee
AFTER DELETE ON employees
FOR EACH ROW
BEGIN
INSERT INTO deleted_employees(emp_id, name)
VALUES (OLD.emp_id, OLD.name);
END //

DELIMITER ;

🧠 How It Works

👉 AFTER DELETE → runs automatically after deletion

👉 OLD.emp_id and OLD.name
Access deleted row values before they disappear

Example

DELETE FROM employees
WHERE emp_id = 101;

Deleted employee info automatically saved in deleted_employees table 💯

🔥 Pro Tip
Triggers are powerful but:
Too many triggers can slow database
Use them carefully 💯

Double Tap ❤️ For More
5
𝗙𝗥𝗘𝗘 𝗗𝗮𝘁𝗮 𝗔𝗻𝗮𝗹𝘆𝘁𝗶𝗰𝘀 𝗖𝗲𝗿𝘁𝗶𝗳𝗶𝗰𝗮𝘁𝗶𝗼𝗻 𝗯𝘆 𝗠𝗶𝗰𝗿𝗼𝘀𝗼𝗳𝘁 & 𝗟𝗶𝗻𝗸𝗲𝗱𝗜𝗻! 🎓

Stop scrolling! This is your chance to get certified by two of the biggest names in tech— 📊 Level up your Data Skills for FREE!

What you get:
• Official Microsoft & LinkedIn Certification
• High-demand Data Analytics skills
• Perfect for your Resume/LinkedIn profile

𝗘𝗻𝗿𝗼𝗹𝗹 𝗙𝗼𝗿 𝗙𝗥𝗘𝗘👇:- 
 
https://pdlink.in/4ubzzcC

👉Don't miss out on this career upgrade. Limited time offer!
3
Which event can activate a trigger?
Anonymous Quiz
12%
A. INSERT
13%
B. UPDATE
1%
C. DELETE
73%
D. All of the above
1
Which trigger type runs before data is inserted?
Anonymous Quiz
16%
A. AFTER INSERT
69%
B. BEFORE INSERT
6%
C. BEFORE DELETE
9%
D. AFTER UPDATE
4
𝗣𝗮𝘆 𝗔𝗳𝘁𝗲𝗿 𝗣𝗹𝗮𝗰𝗲𝗺𝗲𝗻𝘁 𝗣𝗿𝗼𝗴𝗿𝗮𝗺 𝗧𝗼 𝗕𝗲𝗰𝗼𝗺𝗲 𝗮 𝗝𝗼𝗯-𝗥𝗲𝗮𝗱𝘆 𝗦𝗼𝗳𝘁𝘄𝗮𝗿𝗲 𝗗𝗲𝘃𝗲𝗹𝗼𝗽𝗲𝗿🔥

No upfront fees. Learn first, pay only after you get placed! 💼

🚀 What You’ll Get:
Full Stack Development Training
GenAI + Real Industry Projects
Live Classes & 1:1 Mentorship
Mock Interviews & Resume Support
500+ Hiring Partners
Average Package: 7.4 LPA

🎯 Ideal for:- Freshers , College Students, Career Switchers & Anyone looking to enter Tech

💻 Learn In-Demand Skills & Build Your Dream Tech Career!

𝐑𝐞𝐠𝐢𝐬𝐭𝐞𝐫 𝐍𝐨𝐰 👇:-

 https://pdlink.in/42WOE5H

Hurry! Limited seats are available.🏃‍♂️
🤣2
How to Crack a Data Analyst Job Faster

1️⃣ Fix Your Resume
- One page, clean layout, show impact (not tools)
- Example: Improved sales reporting accuracy by 18% using SQL & Power BI
- Add links: GitHub, Portfolio, LinkedIn

2️⃣ Prepare Smart for Interviews
- SQL: joins, window functions, CTEs (daily practice)
- Excel: case questions (pivots, formulas)
- Power BI/Tableau: explain one dashboard end-to-end
- Python: pandas (groupby, merge, missing values)

3️⃣ Master Business Thinking
- Ask why the data exists
- Translate numbers into decisions
- Example: High month-2 churn → poor onboarding

4️⃣ Build a Strong Portfolio
- 3 solid projects > 10 weak ones
- Projects:
- Customer churn analysis
- Sales performance dashboard
- Marketing funnel analysis

5️⃣ Apply With Strategy
- Apply to 5-10 roles daily
- Customize resume keywords
- Reach out to hiring managers (referrals = 3x interviews)

6️⃣ Track Progress
- Maintain interview log
- Fix gaps weekly

🎯 Skills get you shortlisted. Thinking gets you hired.
6
𝗙𝗥𝗘𝗘 𝗢𝗻𝗹𝗶𝗻𝗲 𝗠𝗮𝘀𝘁𝗲𝗿𝗰𝗹𝗮𝘀𝘀 𝗢𝗻 𝗗𝗮𝘁𝗮 𝗔𝗻𝗮𝗹𝘆𝘁𝗶𝗰𝘀 ( 𝗕𝘂𝘀𝗶𝗻𝗲𝘀𝘀 𝗔𝗻𝗮𝗹𝘆𝘁𝗶𝗰𝘀)😍

Learn the Latest 5 Analytics Tools in 2026

Learn Essential skills to stay competitive in the evolving job market

Eligibility :- Students ,Graduates & Working Professionals 

𝗥𝗲𝗴𝗶𝘀𝘁𝗲𝗿 𝗙𝗼𝗿 𝗙𝗥𝗘𝗘 👇:-

https://pdlink.in/4tFlovr

(Limited Slots ..HurryUp🏃‍♂️

𝐃𝐚𝐭𝐞 & 𝐓𝐢𝐦𝐞:- 20th May 2026, at 7 PM
1
Which command permanently saves changes?
Anonymous Quiz
6%
A. ROLLBACK
39%
B. SAVEPOINT
53%
C. COMMIT
2%
D. DELETE