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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 join help

Author  Topic 

apka
Starting Member

1 Post

Posted - 2011-07-15 : 10:56:53
New to joins, please help..

Please find here are desc of 3 tables:

Table-A
AID CName Qty col4 col5
1 Client1 10.8
2 Client2 15.8

Table-B
BID AID TType col4 col5
1 . .
. . .
186 1 ground
187 1 freight
188 1 other
. . .
193 2 ground
194 2 freight

Table-C
CID BID product prod_desc prod_dimension
1 186 steel
2 187 steel
3 188 coal
. . .
6 193 steel
7 194 aluminium

I want to get all AIDs from Table-A where
Qty > 10
having
all 'grounds' (Table-B:TType) which were 'steel' (Table-C:product)
+
all 'freights'(Table-B:TType) which were 'aluminium' (Table-C:product)

Thanks a lot!


livezone
Starting Member

10 Posts

Posted - 2011-07-18 : 13:50:15
select *
from A t1
inner join B t2 on t1.aid = t2.aid
inner join C t3 on t2.bid = t3.bid
Where t1.Qty > 10
and
(
(ttype = 'ground' and product = 'steel' )
Or
(ttype = 'freight' and product = 'aluminium' )
)
Go to Top of Page
   

- Advertisement -