SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 execute query without joins
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

bhavesh205
Starting Member

2 Posts

Posted - 04/10/2013 :  15:03:43  Show Profile  Reply with Quote
Hi frds,

Do anyone know how to replace joins?

Suppose i have 2 tables, one is department and the other is employee.

Dept
______________________
deptno deptname
------------------------
10 finance
20 support
30 sales
______________________
employee
___________________
empid deptno
---------------------
ABC 10
DEF 20
GHI 20

now i want number of employee in each department with department having 0 employee also like below but without any joins.

Deptno count
-----------------------
10 1
20 2
30 0

waiting for ans..

James K
Flowing Fount of Yak Knowledge

3704 Posts

Posted - 04/10/2013 :  15:09:07  Show Profile  Reply with Quote
The best way would be to do joins, so I am not clear why you want to avoid joins. Are you running into any problems? If you must avoid joins, you could use outer apply (but I think of it being sort of like a join): http://technet.microsoft.com/en-us/library/ms175156(v=SQL.105).aspx
Go to Top of Page

Lamprey
Flowing Fount of Yak Knowledge

4614 Posts

Posted - 04/10/2013 :  15:54:10  Show Profile  Reply with Quote
Try searching for "correlated subquery" that is another way to avoid a join for some reason.
Go to Top of Page

bhavesh205
Starting Member

2 Posts

Posted - 04/11/2013 :  00:14:09  Show Profile  Reply with Quote
I do have knowledge and i have successfully executed it without any problem but i just want to know is it be possible to execute join without join?
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000