Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 execute query without joins

Author  Topic 

bhavesh205
Starting Member

2 Posts

Posted - 2013-04-10 : 15:03:43
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
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-04-10 : 15:09:07
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
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2013-04-10 : 15:54:10
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 - 2013-04-11 : 00:14:09
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
   

- Advertisement -