Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
One to many relationship INNER JOIN condition
Message
 
 
To
14/02/2011 10:15:43
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2008
Application:
Web
Miscellaneous
Thread ID:
01500073
Message ID:
01500107
Views:
42
>>If you want to make sure that all records are enabled, then
>>
>>select M.Numero
>>from Master M inner join ManyToManyTable MM on M.Numero = MM.NoMaster
>>inner join ChildTable C on MM.NoChildTable = C.Numero
>>group by M.Numero
>>having min(case when C.Enabled = 1 then 1 else 0 end) = 1 -- means all records are enabled
>>and sum(case when C.Enabled = 1 then 1 else 0 end) = count(C.Numero) -- total number of enabled records = total number of joined records
>
>Unfortunately, this does not work either.

What exactly is the requirement here? Can you post some input and a bit of output?

Do you want to only get Master.Numero if all Child records for that Numero (through ManyToManyTable) are Enabled?
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform