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.
| Author |
Topic |
|
1fred
Posting Yak Master
158 Posts |
Posted - 2005-09-13 : 16:47:41
|
| I have 3 tables. One for my customer, one for the emails I'm sending to my customers and one tracking the type of emails I've sent to themCustomercustomer_idemailEmail_sentcustomer_idemail_sent_template_idEmail_sent_templateemail_sent_template_idbusiness_rule_idWhat I want is all my customers who did not receive a specific business rule, 1 for this example. Logically I would do this select:select c.customer_id,c.emailfrom customer cleft outer join email_sent eson es.customer_id = c.customer_idinner join email_sent_template eston est.email_sent_template_id = es.email_sent_template_idand business_rule_id = 1wherees.email_sent_id is nullThis select statement is not working because of the inner join between email_sent_template and email_sent, it completly ignore the left outer join on email_sent and customer. Anyone can see what I want to do. The workaround is to put a left outer join on email_sent_template and then doing a group by having max(business_rule_id) is null but if its possible I'd like to avoid doing that. These tables will have millions of row, so if I can have inner join instead of left outer join I'd appreciate.Thanks |
|
|
rockmoose
SQL Natt Alfen
3279 Posts |
Posted - 2005-09-13 : 18:25:38
|
| [code]select c.customer_id ,c.emailfrom customer c left outer join ( email_sent es inner join email_sent_template est on est.email_sent_template_id = es.email_sent_template_id and business_rule_id = 1 ) on es.customer_id = c.customer_idwhere es.email_sent_id is null[/code] |
 |
|
|
|
|
|