Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
One to many relationship INNER JOIN condition
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2008
Application:
Web
Miscellaneous
Thread ID:
01500073
Message ID:
01500122
Views:
42
>>>You want to get records if ALL child records are Enabled = 0, isn't it?
>>
>>Pretty much, except the condition is in reversed. But, that is not a factor here. It is just a question of the syntax.
>
>
>SELECT * 
>    FROM MasterTable
>INNER JOIN ChildTable ON MasterTable.PK = ChildTable.FK
>INNER JOIN (SELECT ChildTable.FK
>                   SUM(CASE WHEN The Condition goes Here
>                                 THEN 1
>                            ELSE 0 END) AS CondRecs,
>                   COUNT(*) AS AllRecs
>            FROM ChildTable
>            GROUP BY FK) Tbl1
>   ON MasterTable.PK = ChildTable.FK AND
>      ChildTable.CondRecs = ChildTable.AllRecs
>
>
>?

This sounds correct to me as well.
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform