Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
One to many relationship INNER JOIN condition
Message
 
À
14/02/2011 11:35:00
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2008
Application:
Web
Divers
Thread ID:
01500073
Message ID:
01500120
Vues:
39
>>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
?
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform