SQL Server Joins (हिंदी में)

🔗 SQL Server Joins (हिंदी में)

🔗 SQL Server Joins – पूरी जानकारी (हिंदी में)

🧠 परिभाषा (Memory में रखें)

SQL Join का उपयोग दो या दो से अधिक tables के data को एक साथ जोड़ने के लिए किया जाता है, एक common column (key) के आधार पर।

📘 Joins के प्रकार

  • 1. INNER JOIN
  • 2. LEFT JOIN (LEFT OUTER JOIN)
  • 3. RIGHT JOIN (RIGHT OUTER JOIN)
  • 4. FULL JOIN (FULL OUTER JOIN)
  • 5. CROSS JOIN
  • 6. SELF JOIN

🧾 Tables का Demo

CREATE TABLE Students (
  StudentID INT PRIMARY KEY,
  Name NVARCHAR(50)
);

CREATE TABLE Marks (
  StudentID INT,
  Subject NVARCHAR(50),
  Marks INT
);

🎯 INNER JOIN

केवल वही records लाता है जहाँ दोनों tables में matching key होती है।

SELECT s.Name, m.Subject, m.Marks
FROM Students s
INNER JOIN Marks m ON s.StudentID = m.StudentID;

🎯 LEFT JOIN

Left Table (Students) के सभी records और Right Table (Marks) के matching records लाता है।

SELECT s.Name, m.Subject, m.Marks
FROM Students s
LEFT JOIN Marks m ON s.StudentID = m.StudentID;

🎯 RIGHT JOIN

Right Table (Marks) के सभी records और Left Table (Students) के matching records लाता है।

SELECT s.Name, m.Subject, m.Marks
FROM Students s
RIGHT JOIN Marks m ON s.StudentID = m.StudentID;

🎯 FULL JOIN

दोनों tables के सभी records को combine करता है, NULL values के साथ जहाँ match न हो।

SELECT s.Name, m.Subject, m.Marks
FROM Students s
FULL JOIN Marks m ON s.StudentID = m.StudentID;

🎯 CROSS JOIN

हर row को दूसरी table की हर row के साथ जोड़ता है। (Cartesian Product)

SELECT s.Name, m.Subject
FROM Students s
CROSS JOIN Marks m;

🎯 SELF JOIN

जब एक ही table को आपस में ही जोड़ा जाता है।

SELECT A.Name AS Student1, B.Name AS Student2
FROM Students A
JOIN Students B ON A.StudentID != B.StudentID;

🧠 INTERVIEW QUESTIONS (with Answers)

  1. Q: INNER JOIN क्या करता है?
    Ans: केवल matching rows को दोनों tables से निकालता है।
  2. Q: LEFT JOIN और RIGHT JOIN में क्या अंतर है?
    Ans: LEFT में left table की सभी rows, RIGHT में right table की सभी rows आती हैं।
  3. Q: CROSS JOIN क्या है?
    Ans: Cartesian product बनाता है – सभी संभव combinations।
  4. Q: SELF JOIN कब use होता है?
    Ans: जब एक ही table में relationships compare करने हों।
  5. Q: FULL OUTER JOIN कब use होता है?
    Ans: जब दोनों tables से सभी rows चाहिए, भले ही match हो या न हो।

यह पोस्ट Job Oriented Academy द्वारा SQL में JOINs को आसान भाषा में समझाने के लिए बनाई गई है।

Post a Comment

0 Comments