ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Display all records from multiple Tables using Join in SQL Server<p>Hi <a class="username" rel="akhter"> akhter</a>,</p> <p>Refer below sample query.</p> <p><span style="text-decoration: underline;"><strong>SQL</strong></span></p> <pre class="brush: sql">CREATE TABLE #Catagory (CID INT, CName VARCHAR(MAX)) CREATE TABLE #Sections (SecID INT, Secnam VARCHAR(50)) CREATE TABLE #ItemMasterFile(CodeItem INT, Descriptionitem VARCHAR(max),SecID INT,CID INT) CREATE TABLE #Bigbalprd(BID INT, CodeItem INT, SecID INT, CID INT , QTY INT) INSERT INTO #Catagory VALUES(1, &#39;INDIA&#39;) INSERT INTO #Catagory VALUES(2, &#39;INDIA(Cut)&#39;) INSERT INTO #Catagory VALUES(3, &#39;Pakistan&#39;) INSERT INTO #Catagory VALUES(4, &#39;Pakistan(Cut)&#39;) INSERT INTO #Sections VALUES(1, &#39;HR&#39;) INSERT INTO #Sections VALUES(2, &#39;Baby&#39;) INSERT INTO #Sections VALUES(3, &#39;Ladies&#39;) INSERT INTO #Sections VALUES(4, &#39;Mix Rammage&#39;) INSERT INTO #ItemMasterFile VALUES(1, &#39;A&#39;, &#39;1&#39;, &#39;1&#39;) INSERT INTO #ItemMasterFile VALUES(2, &#39;B&#39;, &#39;2&#39;, &#39;2&#39;) INSERT INTO #ItemMasterFile VALUES(3, &#39;C&#39;, &#39;3&#39;, &#39;3&#39;) INSERT INTO #ItemMasterFile VALUES(4, &#39;D&#39;, &#39;4&#39;, null) INSERT INTO #Bigbalprd VALUES(1, &#39;1&#39;, &#39;1&#39;, &#39;1&#39;,&#39;1&#39;) INSERT INTO #Bigbalprd VALUES(2, &#39;3&#39;, &#39;3&#39;, &#39;3&#39;,&#39;1&#39;) INSERT INTO #Bigbalprd VALUES(3, &#39;4&#39;, &#39;4&#39;, null,&#39;1&#39;) INSERT INTO #Bigbalprd VALUES(4, &#39;4&#39;, &#39;4&#39;, null,&#39;1&#39;) SELECT DISTINCT i.Descriptionitem,s.Secnam,c.CName,ISNULL(SUM(b.QTY),0)QTY FROM #ItemMasterFile i LEFT OUTER JOIN #Bigbalprd b ON i.CodeItem = b.CodeItem INNER JOIN #Sections s ON i.SecID = s.SecID INNER JOIN #Catagory c ON c.CID = i.CodeItem GROUP BY i.Descriptionitem,s.Secnam,c.CName DROP TABLE #Catagory DROP TABLE #Sections DROP TABLE #ItemMasterFile DROP TABLE #Bigbalprd</pre> <p><span style="text-decoration: underline;"><strong>Output</strong></span></p> <table border="1"> <tbody> <tr style="height: 15.0pt;"> <td style="height: 15.0pt; width: 48pt;" width="64" height="20"><strong>Descriptionitem</strong></td> <td style="width: 48pt;" width="64"><strong>Secnam</strong></td> <td style="width: 48pt;" width="64"><strong>CName</strong></td> <td style="width: 48pt;" width="64"><strong>QTY</strong></td> </tr> <tr style="height: 15.0pt;"> <td style="height: 15.0pt;" height="20">A</td> <td>HR</td> <td>INDIA</td> <td>1</td> </tr> <tr style="height: 15.0pt;"> <td style="height: 15.0pt;" height="20">B</td> <td>Baby</td> <td>INDIA(Cut)</td> <td>0</td> </tr> <tr style="height: 15.0pt;"> <td style="height: 15.0pt;" height="20">C</td> <td>Ladies</td> <td>Pakistan</td> <td>1</td> </tr> <tr style="height: 15.0pt;"> <td style="height: 15.0pt;" height="20">D</td> <td>Mix Rammage</td> <td>Pakistan(Cut)</td> <td>2</td> </tr> </tbody> </table>https://www.aspforums.net:443/Threads/708897/Display-all-records-from-multiple-Tables-using-Join-in-SQL-Server/https://www.aspforums.net:443/Threads/708897/Display-all-records-from-multiple-Tables-using-Join-in-SQL-Server/Wed, 19 Jun 2019 00:25:00 GMT