Created
February 18, 2011 14:31
-
-
Save joar/71efc3aa5bff219e98d7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
DISTINCT(Email) | |
FROM | |
Activity a, | |
Consumer c, | |
ActivityType t | |
WHERE | |
c.CountryID = '23' | |
AND t.ActivityType = 'Something_Create' | |
AND a.ActivityTypeId = t.ActivityTypeId | |
AND c.ConsumerID = a.ConsumerID | |
AND (SELECT TOP 1 ActivityID | |
FROM Activity aa, ActivityType tt | |
WHERE aa.ActivityTypeId = tt.ActivityTypeId | |
AND aa.ConsumerID = c.ConsumerID | |
AND tt.ActivityType = 'Something_OptIn') > 0 | |
AND (SELECT TOP 1 ActivityID | |
FROM Activity aa, ActivityType tt | |
WHERE aa.ActivityTypeId = tt.ActivityTypeId | |
AND aa.ConsumerID = c.ConsumerID | |
AND tt.ActivityType = 'Something_OptOut') = NULL | |
-- Returns 0 rows | |
-------------------------- | |
-------------------------- | |
-- Works fine | |
SELECT | |
DISTINCT(Email) | |
FROM | |
Activity a, | |
Consumer c, | |
ActivityType t | |
WHERE | |
c.CountryID = '23' | |
AND t.ActivityType = 'Something_Create' | |
AND a.ActivityTypeId = t.ActivityTypeId | |
AND c.ConsumerID = a.ConsumerID | |
AND (SELECT TOP 1 ActivityID | |
FROM Activity aa, ActivityType tt | |
WHERE aa.ActivityTypeId = tt.ActivityTypeId | |
AND aa.ConsumerID = c.ConsumerID | |
AND tt.ActivityType = 'Something_OptIn') > 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment