SQL INTERVIEW NOTES 2026
1) In what sequence SQL statements are processed?
“Although we write SELECT first, SQL engine processes the query logically in this order:
FROM (Data kahan se lena hai) → JOIN (Table combine) → WHERE (Condition
lagti hai) → GROUP BY(Same type ka data group banana) → HAVING (Group
filter karna (after grouping)) → SELECT(Final output me kya chahiye) →
DISTINCT(Duplicate hata do) → ORDER BY(Sorting karna) → LIMIT(Kitne records tak
output chahiye).
FROM → JOIN → WHERE → GROUP BY → HAVING → SELECT → DISTINCT →
ORDER BY → LIMIT FJWGHSDOL
This helps in understanding why we cannot use column aliases in WHERE but can
use them in ORDER BY.”
🔹 Important Interview Point
❓ Why alias cannot be used in WHERE?
👉 Kyunki WHERE SELECT se pehle execute hota hai, aur alias SELECT me banta
hai.
2) Can we write a distributed query and get some data that is located on another
server and on Oracle Database?
“Yes, Oracle me hum distributed query likh sakte hain to fetch data from
another server or remote database using a Database Link.
Database link ek logical connection hota hai local aur remote Oracle database
ke beech, jiske through hum @dblink_name use karke remote tables ko access kar
sakte hain.”
🔹 Example Line (Bolne layak):
“For example:
SELECT * FROM employees@remote_db_link;
Isse hum remote database ke data ko local table ki tarah query kar sakte hain.”
3) If we drop a table, does it also drop related objects like constraints, indexes,
columns, defaults, Views, and Stored Procedures?
✅ Interview Answer:
“Yes, jab hum DROP TABLE karte hain, to table ke saath uske dependent objects
automatically drop ho jaate hain jaise constraints and indexes.
Lekin views, stored procedures, triggers jaise objects automatically drop nahi hote, balki
invalid ho jaate hain.”
🔹 Object-wise Breakdown (Bolne layak points):
Constraints (PRIMARY KEY, FOREIGN KEY, UNIQUE, CHECK) → ❌ Dropped
Indexes (table ke saath created) → ❌ Dropped
Columns & defaults → ❌ Table ke saath drop
Views → ❌ Not dropped, become INVALID
Stored Procedures / Functions → ❌ Not dropped, become INVALID
4) Can we add an identity column to the decimal datatype?
SQL Server
DECIMAL / NUMERIC datatype par IDENTITY column allowed hai
sirf tab, jab scale = 0 ho.
✔ Valid:
id DECIMAL(10,0) IDENTITY(1,1)
5) What is the difference between LEFT JOIN with WHERE clause & LEFT JOIN with
nowhere clause?
“LEFT JOIN me condition kahan likhi hai ye bahut important hota hai.
Agar right table ki condition ON clause me likhte hain, to LEFT JOIN ka behavior same rehta
hai aur left table ka pura data aata hai.
Lekin agar wahi condition WHERE clause me likh di, to join ke baad filtering hoti hai aur NULL
rows remove ho jaati hain, jis se LEFT JOIN INNER JOIN jaisa behave karne lagta hai.”
6) What are the multiple ways to execute a dynamic query?
“Dynamic SQL execute karne ke multiple ways hote hain, depending on the database and
requirement.
Mainly hum EXEC / EXECUTE, sp_executesql, aur Prepared Statements ka use karte hain.”
🧠 Yaad Rakhne ka Shortcut
EXEC → simple
sp_executesql → safe & fast
Prepared Statement → best practice
7) What is the Difference between COALESCE() & ISNULL()?
“COALESCE() aur ISNULL() dono NULL handle karne ke liye use hote hain,
lekin COALESCE SQL standard function hai aur multiple expressions ko check kar sakta
hai,
jabki ISNULL SQL Server specific function hai jo sirf do arguments accept karta hai.”
8) How do you generate file output from SQL?
“SQL se file output generate karne ke multiple ways hote hain, aur method depend karta hai
database aur environment par.
Commonly hum BCP / SQLCMD, SSIS, Stored Procedures, ya application-level export ka
use karte hain.”
1️⃣ BCP (Bulk Copy Program – SQL Server)
“BCP command ka use karke query ka output CSV / TXT file me export kar sakte hain.”
bcp "SELECT * FROM Employees" queryout [Link] -c -T
👉 Fast, command-line based
👉 Large data ke liye best
2️⃣ SQLCMD Utility
sqlcmd -S ServerName -d DBName -Q "SELECT * FROM Employees" -o [Link]
👉 Simple automation & scripting ke liye useful
3️⃣ SSIS (SQL Server Integration Services)
“SSIS packages use karke SQL data ko CSV, Excel, Flat File me export kiya jata hai.”
👉 Enterprise & scheduled jobs ke liye best
4️⃣ Stored Procedure + OPENROWSET / BULK (Advanced)
“Stored procedure ke through bhi file generate kar sakte hain, but server permissions required
hoti hain.”
5️⃣ Application Layer Export
“Mostly production me SQL query run karke data application ya reporting tool ke through file
me export hota hai.”
9) How do you prevent SQL Server from giving you informational messages during
and after a SQL statement execution?
“SQL Server me informational messages jaise ‘(10 rows affected)’ ko suppress karne ke liye hum
SET NOCOUNT ON use karte hain.
Ye statement execution ke during aur after me row count messages ko stop kar deta hai.”
Why This Is Used? (Experienced Point)
“NOCOUNT ON network traffic reduce karta hai aur application performance improve karta hai,
especially jab stored procedures me multiple statements hote hain.”
10) By Mistake, Duplicate records exists in a table, how can we delete the
copy of a record?
“Agar table me duplicate records by mistake aa gaye hain, to hum ROW_NUMBER() window
function ka use karke duplicates identify karte hain aur extra copies delete kar dete hain, while
keeping one valid record.”
👉 Example:
WITH CTE AS (
SELECT *,
ROW_NUMBER() OVER (
PARTITION BY EmpId, Name, Salary
ORDER BY EmpId
) AS rn
FROM Employees
DELETE FROM CTE
WHERE rn > 1;
🧠 Explanation (Interview Style):
PARTITION BY → duplicate define karta hai
ROW_NUMBER() → har duplicate ko number deta hai
rn > 1 → extra copies delete karta hai
rn = 1 → ek record safe rehta hai
11) WHAT OPERATOR PERFORMS PATTERN MATCHING?
✅ Interview Answer (Hinglish)
“In SQL, pattern matching ke liye LIKE operator use hota hai.
Ye wildcard characters ke through data ko match karta hai.”
🔹 Common Wildcards (Bolne layak)
% → zero ya more characters
_ → exactly one character
🔹 Example (Easy)
SELECT *
FROM Employees
WHERE Name LIKE 'A%';
👉 Names jo A se start hote hain
WHERE Name LIKE '_a%';
👉 Second character ‘a’ ho
🔥 Extra Point (Experienced Touch)
“SQL Server me advanced pattern matching ke liye LIKE ke saath [] aur NOT LIKE bhi use kar
sakte hain.”
WHERE Name LIKE '[A-C]%';
12) What’s the logical difference, if any, between the following SQL
expressions?
✅ Question Recap
Difference between:
SELECT COUNT(*) FROM Employees;
SELECT SUM(1) FROM Employees;
✅ Interview Answer (Hinglish)
“COUNT(*) aur SUM(1) dono table ke rows ko count karne ke liye lagbhag same behave
karte hain jab table me data ho.
Lekin logically difference ye hai ki:
COUNT(*) 0 return karta hai agar table empty ho
SUM(1) NULL return karta hai agar table empty ho
Isliye empty table case me result different hoga.”
13) Is it possible to update the Views? If yes, How, If Not, Why?
“Haan, views ko update karna possible hai, lekin kuch conditions ke saath.
Agar view single base table se bana ho aur koi complex operation na ho (jaise GROUP BY,
DISTINCT, aggregate functions, joins), to INSERT, UPDATE, DELETE directly view par ho sakta
hai.
Agar view complex ho, to direct update allowed nahi, aur uske liye INSTEAD OF trigger ya
base table update karna padta hai.”
🔹 Rules for Updatable Views (Experienced Touch)
1. Simple View → Single table, no aggregates, no GROUP BY, DISTINCT → direct update
allowed
2. Complex View → Jo joins, aggregates, DISTINCT, UNION ya subquery use kare → direct
update NOT allowed
3. INSTEAD OF Trigger → Complex view par insert/update/delete chahiye to trigger define karte
hain
🔹 Example
Simple Updatable View
CREATE VIEW vw_Employees AS
SELECT EmpId, Name, Salary
FROM Employees;
UPDATE vw_Employees
SET Salary = Salary + 1000
WHERE EmpId = 1;
14) Could you please name different kinds of Joins available in SQL
Server?
“SQL Server me humare paas different types of joins hote hain, jo table ke data ko combine karne
ke liye use hote hain. Main common joins ye hain:”
🔹 List of Joins
JOIN ka मतलब kya hota hai?
SQL JOIN ka use hota hai jab:
👉 Data ek table me complete nahi hota
👉 Information dusri table me hoti hai
👉 Dono ko combine करके result निकालना होता है
Real Life Example:
मान लो:
Employees table me employee ka नाम है
Departments table me department ka नाम है
अब employee ko department ke साथ दिखाना है → JOIN लगेगा
🧾 Tables Example
Employees
EmpI Nam DeptI
D e D
1 Akhil 10
2 Ravi 20
3 Neha 30
Ama
4 NULL
n
Departments
DeptI DeptNam
D e
10 HR
20 IT
40 Finance
1️⃣ INNER JOIN
✅ Only Matching Data
👉 Sirf wahi rows आएंगी jinka match dono tables me hai
SELECT [Link], [Link]
FROM Employees e
INNER JOIN Departments d
ON [Link] = [Link];
Output:
Nam DeptNam
e e
Akhil HR
Ravi IT
समझो:
Akhil ka DeptID = 10 → HR मिला
Ravi ka DeptID = 20 → IT मिला
Neha ka DeptID = 30 → Dept table me nahi मिला → remove
Aman ka DeptID NULL → remove
📌 INNER JOIN = Common part only
2️⃣ LEFT JOIN
✅ Left Table ka sab data + Matching Right
👉 Employees sab दिखेंगे, chahe dept मिले ya nahi
SELECT [Link], [Link]
FROM Employees e
LEFT JOIN Departments d
ON [Link] = [Link];
Output:
Nam DeptNam
e e
Akhil HR
Ravi IT
Neha NULL
Ama
NULL
n
समझो:
Akhil + Ravi match ho gaye
Neha ka dept missing → NULL
Aman ka dept NULL → NULL
📌 LEFT JOIN = Left table always complete
3️⃣ RIGHT JOIN
✅ Right Table ka sab data + Matching Left
👉 Departments sab दिखेंगे, chahe employee ho ya nahi
SELECT [Link], [Link]
FROM Employees e
RIGHT JOIN Departments d
ON [Link] = [Link];
Output:
Nam DeptNam
e e
Akhil HR
Nam DeptNam
e e
Ravi IT
NULL Finance
समझो:
Finance department hai लेकिन usme koi employee नहीं है
→ employee column NULL
📌 RIGHT JOIN = Right table always complete
4️⃣ FULL OUTER JOIN
✅ Dono tables ka full data
👉 Match bhi आएगा + unmatched bhi
SELECT [Link], [Link]
FROM Employees e
FULL OUTER JOIN Departments d
ON [Link] = [Link];
Output:
Nam DeptNam
e e
Akhil HR
Ravi IT
Neha NULL
Ama
NULL
n
NULL Finance
📌 FULL JOIN = Left + Right दोनों complete
5️⃣ CROSS JOIN
✅ Every combination
👉 Har employee हर department ke saath जुड़ जाएगा
SELECT [Link], [Link]
FROM Employees e
CROSS JOIN Departments d;
अगर 4 employees और 3 departments:
📌 Output rows = 4 × 3 = 12 rows
Use case:
Testing
All possible combinations
6️⃣ SELF JOIN
✅ Table joins with itself
जब table me hierarchy हो
Example:
EmpI Nam ManagerI
D e D
1 Akhil NULL
2 Ravi 1
3 Neha 1
अब employee + manager name निकालना है:
SELECT [Link] AS Employee, [Link] AS Manager
FROM Employees A
JOIN Employees B
ON [Link] = [Link];
📌 Self join = Same table relation
⭐ Best Trick to Remember JOIN
JOIN याद रखने का
Type तरीका
INNER Common only
LEFT Left पूरा
RIGHT Right पूरा
FULL दोनों पूरा
All
CROSS
combinations
SELF Same table
✅ Interview Line (Perfect)
JOIN is used to combine rows from two or more tables based on a related column between
them.
15) How important do you consider cursors or while loops for a
transactional database?
“Cursors aur WHILE loops ka use transactional databases me possible hai, lekin heavy operations
ke liye avoid karna chahiye.
Reason ye hai ki ye row-by-row (RBAR – Row By Agonizing Row) processing karte hain, jo
performance me bahut slow hota hai.
Transactional systems me hum set-based operations (bulk operations) prefer karte hain because ye
faster aur scalable hote hain.”
🔹 Key Points (Experienced Touch)
1. Cursors
o Use tab karte hain jab row-by-row logic mandatory ho
o Performance overhead zyada
o Mostly last-resort solution
2. WHILE Loops
o Simple iterative logic ke liye
o Large data sets ke liye inefficient
3. Set-Based Operations
o UPDATE, INSERT, DELETE queries directly on tables
o Efficient, scalable, transactional safe
16) What is a correlated subquery?
“A correlated subquery ek aisi subquery hoti hai jo outer query ke column se refer
karti hai.
Matlab subquery har row ke liye execute hoti hai, aur outer query ke current row
par depend karti hai.”
🔹 Key Points (Experienced Touch)
1. Outer query ka column use hota hai
2. Row-by-row evaluation hoti hai
3. Usually WHERE / HAVING clause me use hoti hai
4. Performance normal subquery se slow ho sakti hai, large tables me
17) What is faster, a correlated subquery or an inner join?
“Generally, INNER JOIN faster hota hai compared to a correlated subquery.
Reason ye hai ki correlated subquery row-by-row evaluation karta hai — har row ke liye subquery
execute hoti hai, jo performance heavy hoti hai.
Jabki INNER JOIN set-based operation hai, jo SQL engine ke optimizer ke liye efficient hota hai.”
🧠 Memory Trick
Correlated subquery = Row-by-row = Slow
Inner join = Set-based = Fast
18) You are supposed to work on SQL optimization and given a
choice which one runs faster, a correlated subquery or an exists?
“Generally, EXISTS faster hota hai than a correlated subquery when checking for existence.
Reason ye hai ki EXISTS short-circuits — jaise hi matching row mil jati hai, subquery stop ho jata
hai.
Correlated subquery me har row ke liye full evaluation hoti hai, jo slow ho sakti hai on large tables.”
🧠 Memory Trick
EXISTS = Short-circuit = Fast
Correlated Subquery = Full scan = Slow
19) Can we call. DLL from the SQL server?
“Yes, SQL Server me hum DLLs (Dynamic Link Libraries) call kar sakte hain using CLR integration.
Iske liye hum .NET assembly ko SQL Server me register karte hain aur phir stored procedure,
function, ya trigger ke through call karte hain.”
20) What are the pros and cons of putting a scalar function in a
queries select list or in the where clause?
“Scalar function ko SELECT list me use karna readability ke liye okay hai, lekin performance slow
ho sakti hai kyunki function har row par run hoti hai.
WHERE clause me scalar function use karna avoid karna chahiye, kyunki query non-sargable ho jati
hai, indexes use nahi hote aur performance bahut slow ho jati hai.”
🧠 One-Line Memory Trick
SELECT = OK but slow
WHERE = Avoid (index + performance issue)
21) What are user-defined data types and when you should go for
them?
User-Defined Data Types (UDDTs) wo custom data types hote hain jo hum existing system data
types (like INT, VARCHAR) se banate hain.
Inka use hum consistency, reusability aur data standardization ke liye karte hain.
🔹 When to Use UDDTs?
Jab same datatype + same size baar-baar use ho raha ho
(e.g. MobileNumber, PAN, StatusCode)
Jab business rules ko standard rakhna ho
Jab schema maintainability improve karni ho
🧠 One-Line Memory Trick
Same structure everywhere → Use UDDT
22) Can You Explain Integration Between SQL Server 2005 And
Visual Studio 2005?
SQL Server 2005 aur Visual Studio 2005 ka integration mainly database development aur BI
solutions ke liye hota hai.
Visual Studio 2005 se hum SQL objects, SSIS, SSRS aur CLR code directly develop, debug aur
deploy kar sakte hain.
🔹 Key Integration Points
Database Projects
→ Tables, Views, SPs, Functions ko VS se manage
SSIS Packages
→ ETL development in Visual Studio
SSRS Reports
→ Report design & deployment
CLR Integration
→ C# / [Link] code ko SQL Server me use karna
🧠 One-Line Memory Trick
Visual Studio = Development Tool
SQL Server = Execution Engine
23) What are Index, cluster index, and non-cluster index?
Index
Index SQL Server ka ek performance object hota hai jo data ko fast search / retrieve karne me help
karta hai, bilkul book ke index ki tarah.
🔹 Clustered Index
Clustered index table ke actual data ko sort aur store karta hai.
Ek table me sirf 1 clustered index ho sakta hai.
👉 Example: Primary Key by default clustered hoti hai.
🔹 Non-Clustered Index
Non-clustered index data ka separate structure hota hai jo pointer ke through actual data ko
refer karta hai.
Ek table me multiple non-clustered indexes ho sakte hain.
🧠 One-Line Memory Trick
Clustered = data itself
Non-clustered = pointer to data
24) Write down the general syntax for a SELECT
statement covering all the options.
General SELECT Statement Syntax (Interview Style)
SELECT [DISTINCT] column_list
FROM table_name
[JOIN table ON condition]
[WHERE condition]
[GROUP BY column_list]
[HAVING condition]
[ORDER BY column_list];
🧠 Logical Execution Order (Experienced Touch)
FROM → JOIN → WHERE → GROUP BY → HAVING → SELECT → ORDER BY
🔑 One-Line Memory Trick
Data kaha se → filter → group → filter group → show → sort
25). What is a join and explain different types of joins?
JOIN ka use do ya zyada tables ke related data ko common column ke basis par combine karne ke
liye hota hai.
🔹 Types of JOINs (Short Explanation)
1️⃣ INNER JOIN
Sirf matching records dono tables se return karta hai.
2️⃣ LEFT JOIN
Left table ka saara data + right table ka matching data, warna NULL.
3️⃣ RIGHT JOIN
Right table ka saara data + left table ka matching data, warna NULL.
4️⃣ FULL OUTER JOIN
Dono tables ka matching + non-matching data return karta hai.
5️⃣ CROSS JOIN
Cartesian product – har row ka combination har row ke saath.
6️⃣ SELF JOIN
Table khud se hi join hoti hai (example: employee–manager).
🧠 One-Line Memory Trick
INNER = common
LEFT / RIGHT = priority table
FULL = everything
CROSS = all combinations
SELF = same table
26) What is the OSQL utility?
OSQL ek command-line utility hai jo SQL Server se connect hone aur T-SQL commands execute
karne ke kaam aati hai.
🔹 Key Points (Short)
Command prompt se SQL queries run kar sakte hain
Scripting & automation ke liye useful
Mostly SQL Server 2000 / early 2005 me use hoti thi
Ab SQLCMD ne replace kar diya hai
🧠 One-Line Memory Trick
OSQL = Old command-line SQL tool
27) What Is the Difference Between OSQL And Query
Analyzer?
OSQL aur Query Analyzer dono SQL Server ke tools hain, lekin use-
case bilkul alag hai.
OSQL ek command-line utility hai jo mainly non-interactive
execution ke liye use hoti hai — jaise batch scripts, automation,
scheduled jobs, deployments.
Isme queries background me run hoti hain aur output text-based hota
hai, isliye ye DBA / ops side ke kaam ke liye suitable hai.
Query Analyzer ek GUI-based interactive tool hai jo developers use
karte hain for writing, testing, debugging aur performance tuning
of queries.
Isme result grids, execution plans aur statistics easily available hote hain,
jo query optimization me help karte hain.
🔍 Real-World Difference (Interviewer-Friendly)
“OSQL is designed for automation and scripting, while Query
Analyzer is designed for interactive query development and
analysis.”
🧠 One-Line Killer Summary
OSQL = Automation + Command Line
Query Analyzer = Development + Analysis
28) What Is Cascade delete/update?
Cascade DELETE / UPDATE ka matlab hota hai ki jab parent table me koi record delete ya update
hota hai, to usse related child table ke records automatically delete ya update ho jaate hain.
🔹 Cascade DELETE
Parent record delete hote hi child table ke dependent records bhi delete ho jaate hain.
👉 Example:
Customer delete → Uske Orders bhi delete
🔹 Cascade UPDATE
Parent table ki primary key update hoti hai, to child table ki foreign key automatically update
ho jaati hai.
🧠 One-Line Memory Trick
Parent change → Child auto change
29) What are some of the join algorithms used when SQL
Server joins tables
SQL Server tables ko join karne ke liye mainly 3 join algorithms use karta hai, jo data size aur indexes
par depend karte hain.
1️⃣ Nested Loop Join
Small table + indexed large table ke liye best.
SQL Server har row ke liye dusri table me matching row dhoondhta hai.
2️⃣ Hash Join
Large tables aur no useful index ho tab use hota hai.
Hash table bana ke matching ki jaati hai.
3️⃣ Merge Join
Jab dono tables sorted (indexed) hoti hain.
Fast hota hai for large, ordered datasets.
🧠 One-Line Memory Trick
Nested = small data
Hash = big data, no index
Merge = sorted data
30) What is the maximum number of tables that can join
in a single query?
SQL Server me theoretically 256 tables tak ek single query me join ki ja sakti hain.
Lekin practically, it depends on query complexity, performance, memory aur optimizer limits.
🔹 Practical Interview Point (Very Important)
Real projects me usually 5–15 tables se zyada join karna avoid kiya jata hai, kyunki:
Query complex ho jati hai
Performance degrade hoti hai
Maintenance difficult hota hai
🧠 One-Line Memory Trick
Theoretical = 256
Practical = jitna kam, utna better
31) What are Magic Tables in SQL Server?
Jab bhi TRIGGER chalti hai, SQL Server 2 temporary tables khud bana deta hai.
Inhi ko Magic Tables kehte hain:
👉 INSERTED
👉 DELETED
Aap inhe khud create nahi karte, ye automatically trigger ke andar milti hain.
🔹 Simple Example (Real Life)
Socho table hai Employees
🟢 INSERT hua
INSERT INTO Employees VALUES (101, 'Amit');
➡ Trigger chalegi
➡ INSERTED table me yeh data hoga:
101 | Amit
➡ DELETED table empty hogi
🔴 DELETE hua
DELETE FROM Employees WHERE EmpId = 101;
➡ Trigger chalegi
➡ DELETED table me old data hoga:
101 | Amit
➡ INSERTED table empty
🔁 UPDATE hua
UPDATE Employees
SET Name = 'Rahul'
WHERE EmpId = 101;
➡ Trigger chalegi
➡ DELETED → old value (Amit)
➡ INSERTED → new value (Rahul)
🧠 Super Easy Yaad Rakhne ka Formula
INSERTED = New data
DELETED = Old data
32) Can we disable a trigger? if yes HOW?
Yes, hum SQL Server me trigger disable kar sakte hain, taaki wo temporarily execute na ho.
🔹 HOW to Disable a Trigger
1️⃣ Disable specific trigger on a table
DISABLE TRIGGER TriggerName ON TableName;
2️⃣ Disable all triggers on a table
DISABLE TRIGGER ALL ON TableName;
3️⃣ Disable trigger at database level
DISABLE TRIGGER TriggerName ON DATABASE;
🔹 Enable Trigger Again
ENABLE TRIGGER TriggerName ON TableName;
🧠 Easy Yaad Rakhne ka Trick
DISABLE = trigger band
ENABLE = trigger wapas chalu
🎯 Interview Tip (Experienced Touch)
Triggers mostly data load, bulk insert ya maintenance ke time temporarily disable kiye jaate hain
33) Why do you need indexing? where is Stored and what
do you mean by schema object? For what purpose we are
using view?
1️⃣ Why do you need Indexing? (Kyu index chahiye)
Indexing ka use data fast search / retrieval ke liye hota hai.
Index bina, SQL Server ko poori table scan karni padti hai, jo slow hota hai.
Example:
Book ka index → page fast milta hai 📘
👉 Where Index is Stored?
Index database ke pages (disk) par separately store hota hai, table ke data ke saath linked hota
hai.
✅ 2️⃣ What is a Schema Object?
Schema object wo object hota hai jo database schema ke andar logically stored hota hai.
Examples:
Table
View
Index
Stored Procedure
Function
Trigger
👉 Schema ek container / namespace jaisa hota hai (jaise [Link])
✅ 3️⃣ Why do we use Views? (View ka purpose)
View ek virtual table hoti hai jo SELECT query par based hoti hai.
Uses:
Security → user ko limited columns dikhana
Complex queries simplify karna
Reusability
Consistent business logic
🧠 Easy Memory Trick
Index = Speed
Schema = Container
View = Virtual Table
34) What is the difference between UNION and UNION
ALL?
🔹 UNION
UNION result set me se duplicate records remove karta hai.
Isliye ye thoda slow hota hai, kyunki sorting/distinct operation hota hai.
🔹 UNION ALL
UNION ALL duplicate records remove nahi karta.
Ye fast hota hai kyunki koi extra processing nahi hoti.
🧠 One-Line Memory Trick
UNION = DISTINCT + Slow
UNION ALL = No DISTINCT + Fast
35) Which system table contains information on
constraints on all the tables created?
SQL Server me constraints ki information mainly system catalog views me stored hoti hai.
🔹 Modern SQL Server (2005+)
[Link] → sabhi objects
[Link] → ALL constraints (PK, FK, UQ, CHECK, DEFAULT)
👉 Specific constraints ke liye:
sys.check_constraints
sys.foreign_keys
sys.key_constraints
🔹 Old / Legacy SQL Server
Pehle versions me sysconstraints table use hoti thi.
🧠 Easy Yaad Rakhne ka Trick
New SQL = [Link]
Old SQL = sysconstraints
35) What are the different Types of Join?
1️⃣ INNER JOIN
Sirf matching records dono tables se return karta hai.
2️⃣ LEFT JOIN (LEFT OUTER JOIN)
Left table ka saara data + right table ka matching data, warna NULL.
3️⃣ RIGHT JOIN (RIGHT OUTER JOIN)
Right table ka saara data + left table ka matching data, warna NULL.
4️⃣ FULL OUTER JOIN
Dono tables ka matching + non-matching data return karta hai.
5️⃣ CROSS JOIN
Cartesian product – har row ka combination har row ke saath.
6️⃣ SELF JOIN
Table khud se hi join hoti hai (example: employee–manager).
🧠 One-Line Memory Trick
INNER = common
LEFT / RIGHT = priority table
FULL = everything
CROSS = all combinations
SELF = same table
36) What is Data-Warehousing?
Data Warehouse ek special database hai jahan organization ka saara important data ek jagah
store hota hai, mainly reports aur analysis ke liye.
🔹 Key Points (Easy Words)
1. Subject-oriented → Data business topics ke hisaab se arrange hota hai (Sales, Customer,
Finance)
2. Integrated → Alag-alag systems ka data clean aur consistent hota hai
3. Time-variant → Historical data bhi store hota hai, trends aur changes dekhne ke liye
4. Non-volatile → Data once store ho gaya, read-only hota hai, delete/update nahi hota
🔹 Easy Real-Life Example
Company ke Sales system + Customer system ka data ek jagah warehouse me aa jata hai
Management monthly sales report aur trend analysis easily bana sakti hai
🔹 One-Line Memory Trick (S I T N)
S = Subject-oriented
I = Integrated
T = Time-variant
N = Non-volatile
37) What is a live lock?
Live lock ek aisi situation hai jahan do ya zyada processes continuously apni request retry
karte rehte hain, lekin koi bhi process kaam complete nahi kar pata, aur system busy rehta
hai.
🔹 Easy Example
Do transaction ek same resource ko access karna chahte hain
Dono continuously lock release aur retry karte hain
Result: system busy, lekin koi progress nahi
🔹 Difference from Deadlock
Feature Deadlock Live lock
Processe
Wait forever Continuously retry
s
Not blocked, but no
Resource Blocked
progress
Resolutio Manual /
Needs logic change
n timeout
🧠 One-Line Memory Trick
Deadlock = stuck / Live lock = busy loop but moving
38) How SQL Server executes a statement with nested
subqueries?
Hum SQL Server me nested subqueries ki baat kar rahe hain — iska matlab hai ek query ke andar
doosri query.
✅ Concept (Easy Words)
Nested Subquery = ek query jo doosri query ke andar likhi hoti hai
SQL Server pehle inner query ko solve karta hai
Fir uska result outer query me use karta hai
Socho: inner query = helper, outer query = main query.
🔹 Example (Step-by-Step)
SELECT Name
FROM Employees
WHERE DeptId IN (
SELECT DeptId
FROM Departments
WHERE Location = 'Delhi'
);
Step 1: Inner query execute hoti hai
SELECT DeptId
FROM Departments
WHERE Location = 'Delhi';
SQL Server Departments table dekhta hai
Location = Delhi filter karta hai
Result: suppose [10, 20] (DeptIds)
Step 2: Outer query execute hoti hai
SELECT Name
FROM Employees
WHERE DeptId IN (10, 20);
SQL Server Employees table check karta hai
Jo employees ka DeptId 10 ya 20 hai, unka Name return karta hai
🔹 Easy Analogy
Inner query = ek chhota helper kaam karta hai
Outer query = main kaam karta hai aur helper se answer leta hai
🔹 Interview me bolne ka Short Version
“SQL Server executes nested subqueries from inside out: pehle inner query run hoti hai, fir uska
result outer query me use hota hai.”
🧠 Memory Trick
Inner → Outer → Result
“Helper first, main second”
39) How do you add a column to an existing table?
existing table me new column add karne ke liye hum ALTER TABLE command use karte hain. Syntax
simple hai:
ALTER TABLE table_name
ADD column_name data_type;
Example ke liye, agar hum Employees table me email column add karna chahte hain:
ALTER TABLE Employees
ADD email VARCHAR(50);
Ye command table me naya column email add kar dega without affecting existing data. Agar column
ko NOT NULL ya default value ke saath add karna ho, toh hum extra constraints bhi specify kar sakte
hain."
40) Can one drop a column from a table?
Yes , hum table se column drop (remove) kar sakte hain using ALTER TABLE command with DROP
COLUMN."
Syntax:
ALTER TABLE table_name
DROP COLUMN column_name;
Example:
ALTER TABLE Employees
DROP COLUMN email;
👉 Isse email column permanently table se remove ho jaata hai.
🧠 One-Line Memory Trick
Drop Column = ALTER TABLE + DROP COLUMN ✅
41) Which statement do you use to eliminate padded
spaces between the month and day values in a function
TO_CHAR(SYSDATE,’Month, DD, YYYY’)?
padded spaces remove karne ke liye hum FM (Fill Mode) format model use karte hain."
Correct Statement:
TO_CHAR(SYSDATE, 'FMMonth, DD, YYYY')
👉 FM extra spaces ko eliminate kar deta hai jo Month format ke saath aate hain.
🧠 One-Line Memory Trick
FM = Format Mask = Remove Extra Spaces ✅
42) Which operator do you use to return all of the rows
from one query except rows are returned in a second
query?
EXCEPT operator use hota hai. Ye first query ke sab rows return karta hai except wo rows jo second
query me duplicate hoti hain.
UNION dono queries ke rows return karta hai without duplicates,
UNION ALL duplicates ke saath return karta hai,
aur INTERSECT sirf common rows return karta hai.”
🧠 One-Line Memory Trick (bonus confidence 😎)
EXCEPT = First − Second
UNION = Merge, no duplicate
UNION ALL = Merge, with duplicate
INTERSECT = Common only
👉 Agar interviewer Oracle bole, to ek line add kar dena:
“Oracle me EXCEPT ki jagah MINUS use hota hai.”
43) How will you create a column alias?
column alias create karne ke liye hum AS keyword use karte hain. Ye column ka temporary name hota
hai jo output me display hota hai."
Syntax:
SELECT column_name AS alias_name
FROM table_name;
Example:
SELECT salary AS Monthly_Salary
FROM Employees;
👉 AS optional hota hai, bina AS ke bhi alias de sakte hain.
🧠 One-Line Memory Trick
Alias = AS = Temporary column name
44) In what sequence SQL statements are processed?
SQL statements logically is order me process hote hain:"
1. FROM – table select hoti hai
2. WHERE – rows filter hoti hain
3. GROUP BY – grouping hoti hai
4. HAVING – group pe condition lagti hai
5. SELECT – columns select hote hain
6. ORDER BY – final result sort hota hai
🧠 One-Line Memory Trick
FROM → WHERE → GROUP BY → HAVING → SELECT → ORDER BY
FWGHSO (From Where Group Having Select Order) 😄
45) How can we determine what objects a user-defined
function depends upon?
User-defined function kin objects par depend karti hai, ye jaanne ke liye hum system catalog / data
dictionary dependency views use karte hain.
In views se pata chalta hai ki function tables, views, procedures ya packages par depend karti hai.
Example (Oracle):
SELECT referenced_name, referenced_type
FROM user_dependencies
WHERE name = 'FUNCTION_NAME';
🧠 Shortcut / Memory Trick (Strong & Short)
Function Dependency = DEPENDENCIES view 🔑
👉 Agar 1 line me bolna ho:
“Function dependencies check karne ke liye system catalog dependency views use hote hain.”
46). What is lock escalation?
Lock escalation ek process hai jisme database multiple row-level ya page-level locks ko
automatically table-level lock me convert kar deta hai, taaki system resources kam use ho aur
performance better rahe.
Ye tab hota hai jab ek transaction bahut zyada rows ko lock kar leta hai.
🧠 Shortcut / Memory Trick
Many small locks → One big lock (Table) 🔒
47) What are the main differences between #temp tables
and @table variables and which one is preferred?
#Temp Table
tempdb me create hoti hai
Indexes & statistics support karti hai
Large data ke liye better hoti hai
Transaction support hota hai (rollback possible)
@Table Variable
Memory-based hoti hai (tempdb me hi store hoti hai internally)
Limited indexing support
Small data ke liye fast hoti hai
Transaction rollback support nahi karta
Which one is preferred?
Small data → @table variable
Large data / complex queries → #temp table ✅
🧠 Shortcut / Memory Trick
Small = @table
Big = #temp
48) What are Checkpoint In SQL Server?
Checkpoint SQL Server ka ek process hota hai jo dirty pages (modified data pages) ko memory se
disk par write kar deta hai.
Iska main purpose hota hai recovery time kam karna agar server crash ho jaaye.
Checkpoint ke baad, database consistent state me aa jaata hai.
Types (short mention – bonus knowledge):
Automatic Checkpoint – SQL Server khud run karta hai
Manual Checkpoint – CHECKPOINT command se
Indirect Checkpoint – recovery time control karta hai
🧠 Shortcut / Memory Trick
Checkpoint = Memory → Disk → Fast Recovery ⚡
👉 One-liner bolni ho to:
“Checkpoint memory ke dirty pages ko disk par write karta hai to reduce recovery time.”
49) Why we use the OPEN XML clause?
OPENXML clause SQL Server me XML data ko relational table format me read aur process karne ke
liye use hota hai.
Isse hum XML nodes aur attributes ko rows aur columns ke form me query kar sakte hain.
Ye mainly XML data ko shred (break) karke database tables me insert ya select karne ke kaam aata
hai.
🧠 Shortcut / Memory Trick
OPENXML = XML → Rows & Columns 🔄
👉 One-liner bolni ho to:
“OPENXML is used to convert XML data into relational row-column format for querying.
50) Can we store PDF files inside the SQL Server table?
Haan, hum PDF files SQL Server table me store kar sakte hain using VARBINARY(MAX)
datatype (ye BLOB type ka kaam karta hai).
Best practice:
Small files → database me store
Large files → file system + DB me path
🧠 Shortcut / Memory Trick
PDF in SQL = VARBINARY(MAX) / BLOB 📄➡️🧱
51) Can we store Videos inside the SQL Server table?
Answer:
Yes, SQL Server me Videos ya large binary data ko FILESTREAM datatype ke through store kiya ja
sakta hai. Ye 2008 me introduce hua tha aur large files ko efficiently handle karta hai.
Memory Trick: Videos = FILESTREAM 🎥
52) Can we hide the definition of a stored procedure from a
user?
Answer:
Haan, stored procedure create karte waqt WITH ENCRYPTION use kar sakte hain. Ye procedure
ka code encrypt kar deta hai, users original definition nahi dekh sakte.
Memory Trick: SP code = WITH ENCRYPTION 🔒
53) What are included columns in SQL Server indexing?
Answer:
Included columns wo non-key columns hote hain jo covering queries me use hote hain aur
performance improve karte hain. Features:
Max 1023 additional columns
nvarchar(max) jaise columns bhi include ho sakte hain
Queries faster execute hoti hain
Memory Trick: Included columns = Cover Queries ✅
54) What is an execution plan? How would you view it?
Answer:
Execution plan ek roadmap hai jo batata hai SQL Server query kaise execute karega.
Developer query performance samajhne ke liye use karta hai.
View karne ke liye: Query Analyzer → Show Execution Plan
Memory Trick: Execution Plan = Query roadmap
55). Explain UNION, MINUS, UNION ALL, INTERSECT?
"These are SQL set operators jo multiple queries ke results ko combine karte hain:
1. UNION: Ye dono queries ke results ko combine karta hai aur sirf distinct rows return karta
hai.
o Duplicate rows automatically remove ho jaati hain.
o Thoda slow hota hai because of distinct operation.
2. UNION ALL: Ye bhi dono queries ke results ko combine karta hai lekin duplicates include
karta hai.
o Fast hota hai because no extra distinct check.
3. MINUS (or EXCEPT in SQL Server): Ye first query ke rows me se wo rows remove karta
hai jo second query me exist karte hain.
o Useful for difference calculation.
4. INTERSECT: Ye sirf common rows return karta hai jo dono queries me exist karti hain.
Examples (conceptually):
UNION = List of all unique employees from 2 departments
UNION ALL = List of all employees including duplicates
MINUS = Employees in Dept A but not in Dept B
INTERSECT = Employees common in both Dept A & Dept B
Memory Trick / Shortcut:
UNION = DISTINCT + Slow
UNION ALL = All + Fast
MINUS/EXCEPT = First - Second
INTERSECT = Common rows ✅
56) Write a Query to display the date after 15 days?
"Agar hume current date ke 15 din baad ka date chahiye, to SQL Server me hum DATEADD()
function use karte hain. Ye date me addition/subtraction karne ke liye use hota hai."
Query:
SELECT DATEADD(dd, 15, GETDATE()) AS 'Date_After_15_Days';
Line-by-Line Explanation:
1. DATEADD(dd, 15, GETDATE()) →
o dd = days
o 15 = 15 din add karna
o GETDATE() = current date
2. AS 'Date_After_15_Days' → column alias, output me friendly name dikhata hai
Output Example:
Agar aaj date 2026-01-31 hai, output = 2026-02-15
Memory Trick / Shortcut:
dd = days, +15 → future date 📅
57) Write a Query to display the date after 12 months?
"Agar hume current date se 12 months baad ka date chahiye, SQL Server me DATEADD()
function use karte hain. Ye months, days, years ke hisaab se date add ya subtract karta hai."
Query:
SELECT DATEADD(mm, 12, GETDATE()) AS 'Date_After_12_Months';
Line-by-Line Explanation:
1. DATEADD(mm, 12, GETDATE()) →
o mm = months
o 12 = add 12 months
o GETDATE() = current date
2. AS 'Date_After_12_Months' → column alias, output me readable name dikhata hai
Output Example:
Agar aaj date 2026-01-31 hai, output = 2027-01-31
Memory Trick / Shortcut:
mm = months, +12 → next year same date 📅
58) Write a Query to display the date before 15 days?
"Agar hume current date se 15 din pehle ka date chahiye, SQL Server me DATEADD() function
use karte hain. Isme negative value dene se date subtract hoti hai."
Query:
SELECT DATEADD(dd, -15, GETDATE()) AS 'Date_Before_15_Days';
Line-by-Line Explanation:
1. DATEADD(dd, -15, GETDATE()) →
o dd = days
o -15 = 15 din subtract karna
o GETDATE() = current date
2. AS 'Date_Before_15_Days' → column alias, output me readable name
Output Example:
Agar aaj date 2026-01-31 hai, output = 2026-01-16
Memory Trick / Shortcut:
dd = days, -15 → past date ⏳
59) Write a Query to display employee details along with exp?
"Agar hume employee ke saare details ke saath unka experience chahiye, to SQL Server me
DATEDIFF() function use karte hain. Ye function do dates ke beech ka difference calculate karta
hai."
Query:
SELECT *, DATEDIFF(yy, doj, GETDATE()) AS 'Exp'
FROM employee;
Line-by-Line Explanation:
1. * → employee table ke sab columns select karta hai
2. DATEDIFF(yy, doj, GETDATE()) →
o yy = difference in years
o doj = date of joining
o GETDATE() = current date
o Output = employee ka experience in years
3. AS 'Exp' → alias name, column me Exp dikhayega
Output Example:
Agar employee ka doj = 2020-01-15 aur aaj date 2026-01-31 hai → Exp = 6
Memory Trick / Shortcut:
Experience = DATEDIFF(yy, doj) ⏳
60) Write a Query to display employee details who is working in
ECE department & who his having more than 3 years of exp?
"Agar hume sirf un employees ke details chahiye jo ECE department me kaam kar rahe hain
aur jinka experience 3 saal se zyada hai, to SQL Server me WHERE clause + DATEDIFF()
function use karte hain."
Query:
SELECT *, DATEDIFF(yy, doj, GETDATE()) AS 'Exp'
FROM employee
WHERE DATEDIFF(yy, doj, GETDATE()) > 3
AND dept_name = 'ECE';
Line-by-Line Explanation:
1. * → employee table ke sab columns select karega
2. DATEDIFF(yy, doj, GETDATE()) AS 'Exp' →
o yy = difference in years
o doj = date of joining
o GETDATE() = current date
o Output = experience of employee in years
3. WHERE DATEDIFF(yy, doj, GETDATE()) > 3 → filter employees jinka experience >3 years
4. AND dept_name = 'ECE' → filter employees jo ECE department me kaam karte hain
Output Example:
Agar Employee1 ka doj = 2020-01-10, dept_name = ECE → Exp = 6 → included
Agar Employee2 ka doj = 2024-05-12, dept_name = ECE → Exp = 2 → excluded
Memory Trick / Shortcut:
Filter = Exp>3 + Dept='ECE' ✅
61) Write a Query to display employee details along with age?
"Agar hume employee ke details ke saath unki age bhi chahiye, to SQL Server me DATEDIFF()
function use karte hain. Ye function do dates ke beech ka difference calculate karta hai."
Query:
SELECT *, DATEDIFF(yy, dob, GETDATE()) AS 'Age'
FROM employee;
Line-by-Line Explanation:
1. * → employee table ke sab columns select karta hai
2. DATEDIFF(yy, dob, GETDATE()) AS 'Age' →
o yy = difference in years
o dob = date of birth
o GETDATE() = current date
o Output = employee ka age in years
3. AS 'Age' → column alias, output me Age dikhayega
Output Example:
Agar dob = 1998-06-15 aur aaj date 2026-01-31 hai → Age = 27
Memory Trick / Shortcut:
Age = DATEDIFF(yy, dob) 👶
62) Write a Query to display employee details whose age >18?
“Agar hume sirf un employees ke details chahiye jinki age 18 saal se zyada hai, to hum
DATEDIFF() function ko WHERE clause ke saath use karte hain.”
Query
SELECT *, DATEDIFF(yy, dob, GETDATE()) AS 'Age'
FROM employee
WHERE DATEDIFF(yy, dob, GETDATE()) > 18;
Line-by-Line Explanation
1. SELECT *
→ employee table ke saare columns select karta hai
2. DATEDIFF(yy, dob, GETDATE()) AS 'Age'
o yy = years
o dob = date of birth
o GETDATE() = current date
o Ye expression employee ki age calculate karta hai
3. WHERE DATEDIFF(yy, dob, GETDATE()) > 18
→ sirf wahi employees dikhata hai jinki age 18 se zyada hai
Real-Life Understanding (Interview me bolne layak)
“Is query me pehle hum age calculate kar rahe hain using DATEDIFF, aur phir WHERE clause me
condition laga rahe hain taaki sirf eligible (18+) employees ka data aaye.”
Memory Trick / Shortcut
Age = DATEDIFF(yy, dob)
Filter = WHERE Age > 18 ✅
63) Write a Query to display the minimum salary of an
employee?
“Agar hume company me sabse kam salary pata karni ho, to SQL Server me MIN() aggregate
function use kiya jata hai. Ye function column ke andar se lowest value return karta hai.”
Query
SELECT MIN(salary) AS 'Minimum_Salary'
FROM employee;
Line-by-Line Explanation
1. MIN(salary)
→ salary column me se sabse chhoti value nikalta hai
2. AS 'Minimum_Salary'
→ output column ko readable naam deta hai
3. FROM employee
→ data employee table se liya ja raha hai
Real-Life Explanation (Interview me bolne layak)
“MIN function database engine ko bolta hai ki salary column scan karo aur jo lowest salary hai wo
return karo. Isme grouping nahi hoti kyunki hume overall minimum chahiye.”
Memory Trick / Shortcut
MIN = Minimum (Lowest) ⬇️
64) Write a Query to display the maximum salary of an
employee?
“Agar hume company me sabse zyada salary pata karni ho, to SQL Server me MAX() aggregate
function use karte hain. Ye function column ki highest value return karta hai.”
Query
SELECT MAX(salary) AS 'Maximum_Salary'
FROM employee;
Line-by-Line Explanation
1. MAX(salary)
→ salary column me se sabse badi value nikalta hai
2. AS 'Maximum_Salary'
→ output column ko clear aur readable naam deta hai
3. FROM employee
→ data employee table se fetch hota hai
Real-Life Explanation (Interview me bolne layak)
“MAX function internally salary column ko scan karta hai aur jo highest salary hoti hai usko result me
return karta hai. Ye mostly highest paid employee identify karne ke liye use hota hai.”
Memory Trick / Shortcut
MAX = Maximum (Highest) ⬆️
65) Write a Query to display the total salary of all employees?
“Agar hume company ke sabhi employees ki total salary calculate karni ho, to SQL Server me
SUM() aggregate function use kiya jata hai. Ye function kisi column ke saare values ko add karta
hai.”
Query
SELECT SUM(salary) AS 'Total_Salary'
FROM employee;
Line-by-Line Explanation
1. SUM(salary)
→ salary column ki saari values add karta hai
2. AS 'Total_Salary'
→ output column ko clear naam deta hai
3. FROM employee
→ data employee table se liya ja raha hai
Real-Life Explanation (Interview me bolne layak)
“SUM function salary column ke har record ko add karta hai aur company ka overall salary expense
batata hai. Ye payroll aur budgeting reports me kaafi use hota hai.”
Memory Trick / Shortcut
SUM = Total / Addition ➕
66) Write a Query to display the average salary of an employee?
“Agar hume employees ki average salary nikalni ho, to SQL Server me AVG() aggregate function
use karte hain. Ye function total salary ko employees ki count se divide karke mean value deta hai.”
Query
SELECT AVG(salary) AS 'Average_Salary'
FROM employee;
Line-by-Line Explanation
1. AVG(salary)
→ salary column ki average (mean) value calculate karta hai
2. AS 'Average_Salary'
→ output column ko readable naam deta hai
3. FROM employee
→ data employee table se aata hai
Real-Life Explanation (Interview me bolne layak)
“AVG function internally SUM(salary) / COUNT(salary) karta hai aur company ka salary benchmark
nikalne me help karta hai. Ye HR aur management reports me kaafi use hota hai.”
Memory Trick / Shortcut
AVG = Average = SUM / COUNT ➗
67) Write a Query to count the number of employees working in
the company?
“Agar hume company me total employees ki count nikalni ho, to SQL Server me COUNT()
aggregate function use kiya jata hai. Ye function table me total rows count karta hai.”
Query
SELECT COUNT(*) AS 'Total_Employees'
FROM employee;
Line-by-Line Explanation
1. COUNT(*)
→ table ki har row count karta hai, chahe column me NULL ho ya nahi
2. AS 'Total_Employees'
→ output column ko clear aur readable naam deta hai
3. FROM employee
→ data employee table se liya ja raha hai
Real-Life Explanation (Interview me bolne layak)
“COUNT(*) table me jitne records hain unko count karta hai, isliye ye company ke overall manpower
strength nikalne ke liye use hota hai.”
Memory Trick / Shortcut
COUNT(*) = Total Rows = Total Employees 👥
68) Write a Query to display the minimum & maximum salary of
the employee?
“Agar hume ek hi query me sabse kam aur sabse zyada salary dekhni ho, to SQL Server me MIN()
aur MAX() aggregate functions ko saath me use karte hain.”
Query
SELECT
MIN(salary) AS 'Min_Salary',
MAX(salary) AS 'Max_Salary'
FROM employee;
Line-by-Line Explanation
1. MIN(salary)
→ salary column me se lowest salary nikalta hai
2. MAX(salary)
→ salary column me se highest salary nikalta hai
3. AS 'Min_Salary', AS 'Max_Salary'
→ output columns ko clear names deta hai
4. FROM employee
→ data employee table se liya jata hai
Real-Life Explanation (Interview me bolne layak)
“Is query se hume company ka salary range pata chalta hai — lowest aur highest pay. Ye HR analysis
aur salary benchmarking ke liye kaafi useful hoti hai.”
Memory Trick / Shortcut
MIN + MAX = Salary Range ⬇️⬆️
69) Write a Query to count the number of employees working in
the ECE department?
“Agar hume sirf ECE department me kaam karne wale employees ki count chahiye, to hum
COUNT() function ke saath WHERE clause use karte hain.”
Query
SELECT COUNT(*) AS 'ECE_Employees'
FROM employee
WHERE dept_name = 'ECE';
Line-by-Line Explanation
1. COUNT(*)
→ ECE department ke total employees (rows) count karega
2. FROM employee
→ data employee table se liya ja raha hai
3. WHERE dept_name = 'ECE'
→ sirf wahi records select honge jo ECE department me hain
4. AS 'ECE_Employees'
→ output column ko clear aur readable naam deta hai
Real-Life Explanation (Interview me bolne layak)
“Is query me pehle WHERE clause se ECE department ke employees filter kiye jate hain, phir COUNT(*)
un filtered records ki total count return karta hai.”
Memory Trick / Shortcut
COUNT + WHERE = Department-wise count ✅
70) Write a Query to display the second max salary of an
employee?
“Agar hume second highest salary nikalni ho, to hum pehle maximum salary find karte hain aur
phir usse chhoti jo sabse badi salary hoti hai, wahi second max hoti hai. Iske liye subquery use
karte hain.”
Query (Most common & interview-safe)
SELECT MAX(salary) AS Second_Max_Salary
FROM employee
WHERE salary < (SELECT MAX(salary) FROM employee);
Line-by-Line Explanation
1. Inner Subquery
SELECT MAX(salary) FROM employee
→ Ye company ki highest salary nikalta hai
2. Outer Query
SELECT MAX(salary)
FROM employee
WHERE salary < (highest salary)
→ Highest salary se chhoti salaries me se jo sabse badi hai
→ wahi second highest salary hoti hai
Real-Life Explanation (Interview me bolne layak)
“Pehle hum top salary nikalte hain, phir usse kam salaries ko consider karte hain aur unme se
maximum le lete hain. Is logic se second highest salary mil jaati hai.”
Important Interview Point ⚠️
Ye query duplicate salaries ko handle karti hai
Agar highest salary multiple employees ki ho, tab bhi result correct aata hai
Memory Trick / Shortcut
Second MAX = MAX (salary < MAX salary) ⬆️⬆️
71) Write a Query to display the third max salary of an
employee?
“Third highest salary nikalne ke liye hum nested subqueries use karte hain.
Logic simple hai:
Pehle highest salary
Phir usse chhoti second highest salary
Phir second se chhoti jo sabse badi ho → third highest salary”
Query (Subquery based – interview favorite)
SELECT MAX(salary) AS Third_Max_Salary
FROM employee
WHERE salary < (
SELECT MAX(salary)
FROM employee
WHERE salary < (
SELECT MAX(salary)
FROM employee
);
Step-by-Step Explanation
Step 1: Highest Salary
SELECT MAX(salary) FROM employee
→ company ki sabse badi salary
Step 2: Second Highest Salary
SELECT MAX(salary)
FROM employee
WHERE salary < (highest salary)
→ highest se chhoti jo sabse badi ho = second max
Step 3: Third Highest Salary
SELECT MAX(salary)
FROM employee
WHERE salary < (second highest salary)
→ second se chhoti jo sabse badi ho = third max
Real-Life Explanation (Interview me bolne layak)
“Har step me hum ek salary level remove karte ja rahe hain.
Pehle top salary, phir second, aur finally jo bachi unme se max nikal kar third highest salary mil jaati
hai.”
Important Interview Point ⚠️
Ye approach duplicate salaries ko safely handle karti hai
Real projects me ranking functions bhi use hote hain (ROW_NUMBER / DENSE_RANK)
Memory Trick / Shortcut
3rd MAX = MAX < 2nd MAX < 1st MAX ⬆️⬆️⬆️
72) Write a Query to display the total salary of employees based
on the city?
“Agar hume city-wise total salary chahiye, to SQL Server me GROUP BY clause ke saath SUM()
aggregate function use karte hain. GROUP BY same city ke employees ko ek group me combine
karta hai.”
Query
SELECT city, SUM(salary) AS Total_Salary
FROM employee
GROUP BY city;
Line-by-Line Explanation
1. SELECT city
→ output me city name dikhayega
2. SUM(salary)
→ har city ke employees ki total salary add karega
3. FROM employee
→ data employee table se liya ja raha hai
4. GROUP BY city
→ same city ke employees ko ek group me laata hai
→ har city ke liye alag total salary calculate hoti hai
Real-Life Explanation (Interview me bolne layak)
“GROUP BY city employees ko city-wise segregate karta hai, aur SUM function har city ke group par
apply hoke total salary nikalta hai. Isse hume location-wise payroll cost milti hai.”
Important Interview Rule ⚠️
👉 Jo column SELECT me aggregate ke bina aata hai, use GROUP BY me likhna mandatory
hota hai.
Memory Trick / Shortcut
GROUP BY = Category wise
SUM = Total
👉 City + SUM = City-wise salary
73) Write a Query to display a number of employees based on
the city?
“Agar hume city-wise employees ki count chahiye, to hum GROUP BY clause ke saath COUNT()
aggregate function use karte hain. GROUP BY same city ke employees ko ek group me le aata hai.”
Query
SELECT city, COUNT(emp_no) AS No_Of_Employees
FROM employee
GROUP BY city;
Line-by-Line Explanation
1. SELECT city
→ output me city ka naam dikhata hai
2. COUNT(emp_no)
→ har city me kitne employees hain unki ginti karta hai
3. FROM employee
→ data employee table se liya ja raha hai
4. GROUP BY city
→ same city ke employees ko ek group me karta hai
→ har city ke liye separate count milta hai
Real-Life Explanation (Interview me bolne layak)
“GROUP BY city employees ko city-wise categorize karta hai, aur COUNT function har city ke group me
total employees nikalta hai. Isse hume location-wise manpower strength milti hai.”
Important Interview Rule ⚠️
👉 SELECT me jo column aggregate nahi hai (city), use GROUP BY me likhna compulsory hota
hai.
Memory Trick / Shortcut
COUNT = Number
GROUP BY = Category
👉 City + COUNT = City-wise employees
74) Write a Query to display the total salary of employees based
on region?
“Agar hume region-wise total salary chahiye, to SQL Server me GROUP BY clause ke saath
SUM() aggregate function use kiya jata hai. GROUP BY same region ke employees ko ek group me
combine karta hai.”
Query
SELECT region, SUM(salary) AS Total_Salary
FROM employee
GROUP BY region;
Line-by-Line Explanation
1. SELECT region
→ output me region ka naam show karta hai
2. SUM(salary)
→ har region ke employees ki total salary add karta hai
3. FROM employee
→ data employee table se liya ja raha hai
4. GROUP BY region
→ same region ke employees ko ek group me laata hai
→ har region ke liye alag total salary calculate hoti hai
Real-Life Explanation (Interview me bolne layak)
“Is query se hume company ka region-wise payroll cost pata chalta hai. Ye management reports aur
budgeting decisions me kaafi useful hota hai.”
Important Interview Rule ⚠️
👉 Non-aggregate columns ko GROUP BY me likhna mandatory hota hai.
Memory Trick / Shortcut
SUM = Total
GROUP BY = Category
👉 Region + SUM = Region-wise salary 🌍💰
75) Write a Query to display the number of employees working
in each region?
“Region-wise employees count nikalne ke liye COUNT() aggregate function ko GROUP BY clause
ke saath use karte hain.”
Query
SELECT region, COUNT(*) AS Total_Employees
FROM employee
GROUP BY region;
Line-by-Line Explanation
1. SELECT region
→ kaunsa region hai, wo show karta hai
2. COUNT(*)
→ har region me kitne employees hain, unko count karta hai
3. AS Total_Employees
→ column ka meaningful alias deta hai
4. FROM employee
→ data employee table se aata hai
5. GROUP BY region
→ same region ke employees ko ek group me combine karta hai
Real-Life Explanation (Interview bolne ke liye)
“Is query se hume pata chalta hai ki kis region me kitne employees kaam kar rahe hain, jo
workforce planning aur resource allocation ke liye useful hota hai.”
Important Interview Point ⚠️
COUNT(*) NULL values bhi count karta hai
Agar specific column count karna ho to:
COUNT(emp_id)
Shortcut / Memory Trick 🧠
COUNT = Number
GROUP BY = Category
👉 Region + COUNT = Region-wise employee count
76) Write a Query to display minimum salary & maximum salary
based on dept_name?
“Department-wise minimum aur maximum salary nikalne ke liye MIN() aur MAX() aggregate
functions ko GROUP BY clause ke saath use karte hain.”
Query
SELECT dept_name,
MIN(salary) AS Min_Salary,
MAX(salary) AS Max_Salary
FROM employee
GROUP BY dept_name;
Line-by-Line Explanation
1. SELECT dept_name
→ kis department ki salary dikhani hai
2. MIN(salary)
→ department ki sabse kam salary
3. MAX(salary)
→ department ki sabse zyada salary
4. AS Min_Salary / Max_Salary
→ output ko readable column name deta hai
5. FROM employee
→ data employee table se aata hai
6. GROUP BY dept_name
→ same department ke employees ko ek group bana deta hai
Real-Life Explanation (Interview style)
“Is query se hum dekh sakte hain ki har department me salary range kya hai, jo compensation
analysis aur budgeting ke liye useful hota hai.”
Important Interview Point ⚠️
GROUP BY me wahi column aata hai jo SELECT me aggregate ke bina likha ho
MIN() / MAX() NULL values ignore karte hain
Shortcut / Memory Trick 🧠
MIN = Lowest
MAX = Highest
GROUP BY dept = Dept-wise result
👉 Dept + MIN/MAX = Salary range
77) Write a Query to display the total salary of employees based
on dept_name?
“Department-wise total salary nikalne ke liye SUM() aggregate function ko GROUP BY clause ke
saath use karte hain.”
Query
SELECT dept_name,
SUM(salary) AS Total_Salary
FROM employee
GROUP BY dept_name;
Line-by-Line Explanation
1. SELECT dept_name
→ kaunsa department hai, wo dikhata hai
2. SUM(salary)
→ us department ke sabhi employees ki total salary nikalta hai
3. AS Total_Salary
→ output ko clear aur readable name deta hai
4. FROM employee
→ data employee table se aata hai
5. GROUP BY dept_name
→ same department ke employees ko ek group bana deta hai
Real-Life Explanation (Interview me bol sakte ho)
“Is query se hume pata chalta hai ki har department par total salary cost kitni aa rahi hai, jo
budgeting aur cost analysis ke liye useful hota hai.”
Important Interview Point ⚠️
SUM() NULL salaries ignore karta hai
GROUP BY ke bina SUM() lagaya to overall total salary milegi, dept-wise nahi
Shortcut / Memory Trick 🧠
SUM = Total
GROUP BY = Category
👉 Dept + SUM = Dept-wise total salary
78) Write a Query to display no. of males in each department?
“Department-wise kitne male employees hain ye nikalne ke liye hum COUNT() aggregate function
ko WHERE clause aur GROUP BY ke saath use karte hain.”
Correct & Proper Query
SELECT dept_name,
COUNT(*) AS No_Of_Males
FROM employee
WHERE gender = 'Male'
GROUP BY dept_name;
Line-by-Line Explanation
1. SELECT dept_name
→ kaunsa department hai, ye show karta hai
2. COUNT(*)
→ har department me male employees ki total count nikalta hai
3. AS No_Of_Males
→ result ko clear column name deta hai
4. FROM employee
→ data employee table se aata hai
5. WHERE gender = 'Male'
→ sirf male employees ko filter karta hai
6. GROUP BY dept_name
→ same department ke male employees ko ek group bana deta hai
Why WHERE before GROUP BY? (Very Important Interview Point 🔥)
WHERE → rows filter karta hai
GROUP BY → filtered rows ko group karta hai
👉 isliye WHERE hamesha GROUP BY se pehle aata hai
Wrong Query (Interview me mat bolna ❌)
SELECT dept_name, COUNT(gender)
FROM employee
GROUP BY dept_name
WHERE gender = 'Male'; -- ❌ syntax error
Real-Life Explanation (Interview Friendly)
“Is query ka use HR analysis me hota hai, jahan department-wise gender distribution analyse karna
hota hai.”
Shortcut yaad rakhne ka 🧠
Filter first → WHERE
Group later → GROUP BY
Count → COUNT(*)
79) Write a Query to display the total salary of employees based
on whose total salary > 12000?
“Jab hume grouped data (jaise city-wise salary) par condition lagani hoti hai, tab hum HAVING clause
ka use karte hain, kyunki WHERE aggregate functions ke saath kaam nahi karta.”
Correct & Proper Query
SELECT city,
SUM(salary) AS Total_Salary
FROM employee
GROUP BY city
HAVING SUM(salary) > 12000;
Line-by-Line Explanation
1. SELECT city
→ kis city ka data dikhana hai
2. SUM(salary)
→ har city ka total salary calculate karta hai
3. AS Total_Salary
→ output column ko readable naam deta hai
4. FROM employee
→ data employee table se aa raha hai
5. GROUP BY city
→ same city ke employees ko ek group bana deta hai
6. HAVING SUM(salary) > 12000
→ sirf wahi cities dikhata hai jinka total salary 12000 se zyada ho
WHERE vs HAVING (🔥 Interview Favorite Question)
Clause Use hota hai
WHERE Individual rows par condition
HAVIN Group / aggregate result par
G condition
❌ Wrong (Interview me mat bolna):
WHERE SUM(salary) > 12000 -- ❌ invalid
Real-Life Example (Interview bol sakte ho):
“Is type ki query payroll analysis me use hoti hai jahan city ya department ka total salary budget check
karna hota hai.”
Shortcut yaad rakhne ka 🧠
GROUP BY → salary jodta hai
HAVING → total par filter lagata hai
Aggregate condition = HAVING
80) Write a Query to display the total salary of all employees
based on a city whose average salary >= 23000?
“Jab hume grouped data par average salary condition lagani hoti hai, tab hum GROUP BY +
HAVING clause use karte hain. HAVING aggregate functions jaise AVG, SUM, COUNT ke saath use hota
hai.”
✅ Correct Query
SELECT city,
SUM(salary) AS Total_Salary
FROM employee
GROUP BY city
HAVING AVG(salary) >= 23000;
✅ Query Explanation (Line by Line)
1️⃣ SELECT city
→ City ka naam dikhane ke liye
2️⃣ SUM(salary) AS Total_Salary
→ Har city ka total salary calculate karega
3️⃣ FROM employee
→ Data employee table se
4️⃣ GROUP BY city
→ Same city ke employees ko group bana deta hai
5️⃣ HAVING AVG(salary) >= 23000
→ Sirf wahi cities show karega jinka average salary 23000 ya usse zyada ho
✅ Simple English Explanation (Interview Trick)
“First, SQL groups employees by city. Then it calculates average salary per city. After that, it filters only
those cities where average salary is greater than or equal to 23000, and finally shows total salary for
those cities.”
🔥 Important Interview Concept
❓ Why HAVING not WHERE?
Clause Use
WHERE Row-level condition
HAVIN Group-level (AVG, SUM, COUNT)
G condition
❌ Wrong:
WHERE AVG(salary) >= 23000
🧠 Shortcut Trick
👉 AVG / SUM / COUNT condition = HAVING
🔥 1) Difference between WHERE and HAVING (with example)
✅ Short Answer (Interview):
WHERE → row-level filter
HAVING → group / aggregate filter
✅ Example
-- WHERE (before grouping)
SELECT * FROM employee
WHERE salary > 20000;
-- HAVING (after grouping)
SELECT city, AVG(salary)
FROM employee
GROUP BY city
HAVING AVG(salary) > 23000;
🧠 Shortcut:
👉 Row filter = WHERE
👉 Group filter = HAVING
🔥 2) Can we use HAVING without GROUP BY?
✅ Answer:
YES, but only when aggregate function use ho raha ho.
✅ Example
SELECT SUM(salary)
FROM employee
HAVING SUM(salary) > 100000;
📌 Explanation:
Pura table ek hi group maan liya jata hai.
🧠 Shortcut:
👉 GROUP BY na ho to bhi HAVING chalega (aggregate ho to)
🔥 3) Can we use WHERE after GROUP BY?
❌ Answer:
NO
❌ Wrong:
GROUP BY city
WHERE salary > 20000
✅ Correct order:
WHERE salary > 20000
GROUP BY city
HAVING SUM(salary) > 50000
🧠 SQL Order yaad rakho (🔥 very important):
👉 SELECT → FROM → WHERE → GROUP BY → HAVING → ORDER BY
🔥 4) Performance: WHERE vs HAVING – which is faster?
✅ Answer:
WHERE is faster
Kyunki WHERE pehle rows kam kar deta hai
HAVING baad me groups par kaam karta hai
✅ Best Practice Example
SELECT city, SUM(salary)
FROM employee
WHERE salary > 15000
GROUP BY city
HAVING SUM(salary) > 50000;
🧠 Shortcut:
👉 Filter early = WHERE
👉 Filter result = HAVING
🔥 5) Interview Trap Question 😈
❓ “Can HAVING replace WHERE?”
✅ Smart Answer:
“No, HAVING aggregate conditions ke liye hota hai, WHERE row-level filtering ke liye. Dono ka role alag
hai.”
🧠 ONE-LINE MASTER SHORTCUT (Yaad rakhna)
WHERE → rows
GROUP BY → groups
HAVING → groups ke result
Agar chaho next round me:
Second / Third max salary (BEST approaches)
GROUP BY + HAVING real business scenarios
SQL Server vs Oracle differences (INTERVIEW GOLD)
81) Write a Query to display employee details whose employee
numbers are 101, 102
✅ Answer (Interview bolne layak):
“Specific values ke basis par multiple records fetch karne ke liye hum IN operator ka use karte hain.”
✅ Correct & Proper Query
SELECT *
FROM employee
WHERE emp_no IN (101, 102);
✅ Query Explanation (Line by Line)
1️⃣ SELECT *
→ Employee ke saare columns fetch karega
2️⃣ FROM employee
→ Data employee table se aayega
3️⃣ WHERE emp_no IN (101, 102)
→ Sirf wahi records dikhayega jinka
employee number 101 ya 102 hai
✅ Why IN operator?
Jab multiple values check karni ho
Clean & readable
OR se better & optimized
❌ Long way (avoid in interview):
WHERE emp_no = 101 OR emp_no = 102;
🔥 Interview Follow-up (Smart Answer)
❓ Difference between IN and =
= → single value
IN → multiple values
🧠 Shortcut Trick
👉 Multiple values = IN
82) Write a Query to display employee details belongs to the
ECE department?
✅ Final Correct Query (Perfect for Interview)
SELECT Emp_No, Emp_Name, Salary
FROM employee
WHERE dept_no IN (
SELECT dept_no
FROM dept
WHERE dept_name = 'ECE'
);
(Quotes 'ECE' single quotes me honi chahiye – interview me ye detail plus point hota hai.)
✅ Answer (Interview bolne ka tareeka):
“Employee ka department name alag table me hota hai, isliye hum subquery with IN operator ka
use karke ECE department ke employees fetch karte hain.
83) Write a Query to display the first record from the table
🔹 Answer (Interview bolne layak)
“First record nikalne ke liye SQL Server me hum TOP clause ka use karte hain.”
🔹 Query
SELECT TOP 1 *
FROM employee;
🔹 Explanation
TOP 1 → sirf ek record laata hai
Agar ORDER BY nahi diya, to SQL table ke natural order me first record de deta hai
⚠️Interview Tip:
Agar interviewer bole “first based on emp_no” to bolna:
ORDER BY emp_no ASC
🧠 Shortcut
👉 First record = TOP 1
84) Write a Query to display the top 3 records from the table
🔹 Answer
“Top N records fetch karne ke liye hum TOP N use karte hain.”
🔹 Query
SELECT TOP 3 *
FROM employee;
🔹 Explanation
TOP 3 → first 3 rows return karega
ORDER BY ke bina random lag sakta hai
✅ Best Practice
SELECT TOP 3 *
FROM employee
ORDER BY emp_no ASC;
🧠 Shortcut
👉 Top N records = TOP N
85) Write a Query to display the last record from the table
🔹 Answer
“Last record nikalne ke liye hum ORDER BY DESC ke saath TOP 1 use karte hain.”
🔹 Query
SELECT TOP 1 *
FROM employee
ORDER BY emp_no DESC;
🔹 Explanation
ORDER BY emp_no DESC → sabse bada emp_no pehle
TOP 1 → wahi last record ban jaata hai
🧠 Shortcut
👉 Last record = TOP 1 + DESC
🔥 SQL SERVER: RANKING FUNCTIONS
86) Write a Query to display student details along with row
number ordered by student name
🔹 Answer
“Sequential row number generate karne ke liye hum ROW_NUMBER() function use karte hain.”
🔹 Query (Corrected)
SELECT *,
ROW_NUMBER() OVER (ORDER BY student_name) AS Row_ID
FROM student;
🔹 Explanation
ROW_NUMBER() → har row ko unique number deta hai
ORDER BY student_name → naam ke order me numbering hoti hai
🧠 Shortcut
👉 Unique sequence = ROW_NUMBER()
87) Write a Query to display EVEN records from the table
🔹 Answer
“ROW_NUMBER ke through numbering karke modulus (%) operator se even rows nikalte hain.”
🔹 Query
SELECT *
FROM (
SELECT *,
ROW_NUMBER() OVER (ORDER BY student_no) AS Row_ID
FROM student
)t
WHERE Row_ID % 2 = 0;
🔹 Explanation
Inner query → row numbers generate karti hai
Row_ID % 2 = 0 → even numbers select karta hai
🧠 Shortcut
👉 Even rows = %2 = 0
88) Write a Query to display ODD records from the student
table
🔹 Answer
“Odd rows ke liye modulus operator ka opposite condition lagate hain.”
🔹 Query
SELECT *
FROM (
SELECT *,
ROW_NUMBER() OVER (ORDER BY student_no) AS Row_ID
FROM student
)t
WHERE Row_ID % 2 != 0;
🔹 Explanation
%2 != 0 → odd numbers
Baaki logic same hai even records jaisa
🧠 Shortcut
👉 Odd rows = %2 != 0
🔥 ONE MASTER INTERVIEW LINE (Yaad rakhna)
TOP → limit rows
ORDER BY → decide order
ROW_NUMBER → generate sequence
%2 → even/odd logic
🔥 MOST IMPORTANT SQL SERVER INTERVIEW QUESTIONS (Miss
mat karna)
🔹 1) Difference between DELETE, TRUNCATE, DROP
👉 Almost har interview me aata hai
One-line answer:
DELETE → row wise, rollback possible
TRUNCATE → full table clean, fast, rollback nahi
DROP → table hi uda deta hai
🧠 Shortcut:
DELETE = data delete
TRUNCATE = data + reset
DROP = structure gone
🔹 2) Clustered vs Non-Clustered Index
👉 Performance question
Short answer:
Clustered → actual data sorted
Non-clustered → pointer hota hai
🧠 Shortcut:
Clustered = data itself
Non-clustered = data ka address
🔹 3) Primary Key vs Unique Key
👉 Tricky but common
Primary → NULL not allowed, one per table
Unique → NULL allowed, multiple allowed
🧠 Shortcut:
Primary = main identity
Unique = extra safety
🔹 4) Index kya hota hai? Kyun use karte hain?
👉 Concept clarity check
Answer:
“Index table ke data ko fast search karne ke liye hota hai, jaise book ka index.”
🧠 Shortcut:
Index = fast SELECT
🔹 5) Normalization kya hai? Types?
👉 Theory + practical
Redundant data remove karna
1NF, 2NF, 3NF (3NF tak kaafi hai)
🧠 Shortcut:
Normalization = no duplication
🔹 6) Denormalization kab karte hain?
👉 Senior level question
Answer:
“Performance improve karne ke liye jab joins slow ho jaate hain.”
🔹 7) Stored Procedure vs Function
👉 Must-ask
SP → DML allowed, no return compulsory
Function → SELECT only, return mandatory
🧠 Shortcut:
SP = actions
Function = calculation
🔹 8) View kya hota hai?
👉 Simple but asked
Answer:
“Virtual table hota hai jo stored query hoti hai.”
🔹 9) Transaction kya hota hai? ACID?
👉 Banking example do
Atomicity
Consistency
Isolation
Durability
🧠 Shortcut:
ACID = safe transaction
🔹 10) Deadlock kya hota hai?
👉 Real scenario
Answer:
“Jab do transactions ek dusre ka resource wait karti hain.”
🧠 Shortcut:
You wait me, I wait you 😄
🔹 11) WHERE vs HAVING
👉 Tum already strong ho isme 💪
🔹 12) JOIN types (INNER, LEFT, RIGHT, FULL)
👉 Diagram based question
🧠 Shortcut:
INNER = common
LEFT = all left
RIGHT = all right
FULL = everything
🔹 13) Second / Third highest salary
👉 Already cover ho chuka, repeat karo
🔹 14) CTE kya hota hai?
👉 Modern SQL
Answer:
“Temporary result set hota hai jo query readability improve karta hai.”
🔹 15) Execution Plan kya hota hai?
👉 Performance interview
Answer:
“SQL ka roadmap hota hai jo batata hai query kaise execute hogi.”
🎯 FINAL INTERVIEW STRATEGY (Important)
👉 Query likhte waqt bolna:
“We can also do this using JOIN”
“This is more optimized”
👉 Agar atko:
Calm raho
Logic explain karo
Exact syntax na aaye to bhi chalega
🧠 ULTIMATE SHORTCUT
Concept clear > Syntax perfect