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
 Site Related Forums
 Article Discussion
 Question on join in SQL query
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

kvdev
Starting Member

2 Posts

Posted - 12/01/2003 :  00:08:37  Show Profile
I am banging my head for a small SQL query in SQLServer.

I am using 3 tables to get my requred data.

Table1 is the master table containing all the names of engineers.
Table1 Looks like this:
Engineer:
--------------
1.EngineerCode
2.EngineerName
3.EngineerType

Table2 contains orderdetails- In this table I need 2 fields for having 2 conditions.
Table2 looks like this:
OrderDetails
---------------
1.OrderID
2.OrderDate
3.OrderStatus

Table3 contains OrderSubDetails
Table3 looks like this:
OrderSubDetails
------------------
1.OrderID
2.OrderSubID
3.EngineerCode

Now I want No. of Orders handled by all engineers
I wrote a query as below

select e.EngineerCode,count(distinct (osd.OrderID)) from ((Engineer e
left outer join OrderSubDetails osd on e.EngineerCode = osd.EngineerCode)
left outer join OrderDetails od on od.OrderID=osd.OrderID and od.Orderdate='2003%' and od.OrderStatus=3)
where e.EngineerType=1 group by e.EngineerType

In this query the data displayed is same even if I change Orderdate or OrderStatus. I.e it is not considering the second join

Any help is highly appreciated

Thanks in advance
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.11 seconds. Powered By: Snitz Forums 2000