SQL Query for joining two tables [Resolved]

Posted by Somu475 under Sql Server on 11/29/2012 | Points: 10 | Views : 1145 | Status : [Member] | Replies : 4
Hi All,

I have 2 tables Emp & Dept, I want to get the output as in 3rd table.

Check the attached file.

Plz some1 send the SQL query for getting the o/p as shown in 3rd table.

-Somu


Responses

Posted by: Pandians on: 11/29/2012 [Member] [MVP] Silver | Points: 50

Up
0
Down

Resolved
Check It Out!
SELECT E.DeptID, COUNT(1) [No of Emp] FROM T_emp E WITH(NOLOCK) JOIN T_Dept D WITH(NOLOCK)

ON (E.DeptID = D.DeptID)
GROUP BY E.DeptID


Cheers
www.SQLServerbuddy.blogspot.com
iLink Multitech Solutions

Somu475, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Somu475 on: 11/29/2012 [Member] Starter | Points: 25

Up
0
Down
Thank u so much... Its working fine...

-Somu

Somu475, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Somu475 on: 11/29/2012 [Member] Starter | Points: 25

Up
0
Down
Hi Sir,

Even I'm getting the required output without using WITH(NOLOCK) in the query as shown below.
SELECT  E.DeptId, COUNT(1) AS [No of Emp]

FROM T_emp E INNER JOIN
T_Dept D ON E.DeptId = D.DeptId
GROUP BY E.DeptId

Then what is the need of using WITH(NOLOCK) in query..?? Is there any advantage..??
Plz explain me briefly...

-Somu

Somu475, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Pandians on: 11/29/2012 [Member] [MVP] Silver | Points: 25

Up
0
Down
Check with "READUNCOMMITTED" Isolation level or "NOLOCK" Table hint on MSDN for deep dive

Cheers
www.SQLServerbuddy.blogspot.com
iLink Multitech Solutions

Somu475, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response