I am having some issues trying to get a query to exclude some individuals from a mailing list. I have 3 tables, one for clients and 1 for program participation and 1 for individuals. Individuals can participate on multiple programs, but I am trying to get only those who have not particpated in the current program.
Tables look like this: (Very simplified)
client_table
h_13Key H13UserID H13FirstName H13LastName
DD6493DD 145 Joe Smith
E08CE1F8 154 Jasmin Smith
9AA95241 127 Susan Someone
DD6493DD 145 Joe Mama
11611C0A 130 Walden Pond
program_results_table
H11userID H11ProgramID H_11Hey
145 101 FF4B1F85
154 101 33D43800
127 103 A33DF48D
127 101 F3FBD1A8
145 102 E678B6BC
145 103 7F7AC520
130 101 E96AFD6A
130 103 6BC57477
Individuals
cst_key cst_firstname cst_lastname
DD6493DD Joe Smith
E08CE1F8 Jasmin Smith
9AA95241 Susan Someone
DD6493DD Joe Mama
11611C0A Walden Pond
5609RTEE Another Guy
R68793AZ Busta Move
90FJKLR76 One More
I need everyone who did not particpate in program 103 or has not participated at all.
Here would be the rough query:
SELECT
h_13Key,
H13UserID,
H13FirstName,
H13LastName,
H11userID,
H11ProgramID,
H_11Hey
FROM client_table
left join individuals on h13Key = cst_key
left join (SELECT H11userID,h11_delete_flag,MAX(H11ProgramID)as progID,h11_resultid FROM program_results_table
Group by H11userID,
h11_delete_flag,
H11ProgramID,
h11_hraresultid
HAVING MAX(H11ProgramID) <'103') as a
on a.H11userID=H13UserID and h11_delete_flag = 0
Where H11ProgramID <> '103 or H11ProgramID is null
I am still getting the records for those with program ID 101 or 102.
I have cut this up to simplify so I hope I didn't find and replace the wrong thing. Any suggestions?
Tables look like this: (Very simplified)
client_table
h_13Key H13UserID H13FirstName H13LastName
DD6493DD 145 Joe Smith
E08CE1F8 154 Jasmin Smith
9AA95241 127 Susan Someone
DD6493DD 145 Joe Mama
11611C0A 130 Walden Pond
program_results_table
H11userID H11ProgramID H_11Hey
145 101 FF4B1F85
154 101 33D43800
127 103 A33DF48D
127 101 F3FBD1A8
145 102 E678B6BC
145 103 7F7AC520
130 101 E96AFD6A
130 103 6BC57477
Individuals
cst_key cst_firstname cst_lastname
DD6493DD Joe Smith
E08CE1F8 Jasmin Smith
9AA95241 Susan Someone
DD6493DD Joe Mama
11611C0A Walden Pond
5609RTEE Another Guy
R68793AZ Busta Move
90FJKLR76 One More
I need everyone who did not particpate in program 103 or has not participated at all.
Here would be the rough query:
SELECT
h_13Key,
H13UserID,
H13FirstName,
H13LastName,
H11userID,
H11ProgramID,
H_11Hey
FROM client_table
left join individuals on h13Key = cst_key
left join (SELECT H11userID,h11_delete_flag,MAX(H11ProgramID)as progID,h11_resultid FROM program_results_table
Group by H11userID,
h11_delete_flag,
H11ProgramID,
h11_hraresultid
HAVING MAX(H11ProgramID) <'103') as a
on a.H11userID=H13UserID and h11_delete_flag = 0
Where H11ProgramID <> '103 or H11ProgramID is null
I am still getting the records for those with program ID 101 or 102.
I have cut this up to simplify so I hope I didn't find and replace the wrong thing. Any suggestions?