I have a phpbb forum using mysql databases. The users are identified by “user_id.” However, they have multiple groups. Users will either be in the “human” (9) or “zombie” (8) group. However, they will always be in the “registered” (2) group. This creates a table that looks like this:

Three databases are used in total to form a new table.
SELECT phpbb_users.user_id 'ID',
IF( phpbb_user_group.group_id =9, 'Human', IF( phpbb_user_group.group_id =8, 'Zombie', '')) AS Team,
IF( phpbb_profile_fields_data.pf_oz =1, 'Yes', ' ' ) AS OZ,
phpbb_users.username 'Player', phpbb_users.user_email 'E-mail',
IF( phpbb_profile_fields_data.pf_share_phonenum =1, phpbb_profile_fields_data.pf_phone_number, ' ' ) AS Phone,
phpbb_profile_fields_data.pf_code 'Tag Code',
phpbb_profile_fields_data.pf_student_id 'Student ID', phpbb_users.starve 'Time Remaining (in hours)'
FROM phpbb_profile_fields_data, phpbb_users, phpbb_user_group
WHERE phpbb_profile_fields_data.user_id = phpbb_users.user_id
AND phpbb_profile_fields_data.user_id = phpbb_user_group.user_id
LIMIT 0 , 300
I need all the rows with blank fields under “Team” (which are the result of the “registered” group) removed from the result set. All help is appreciated!
Add a
HAVINGclause to the end of yourWHEREclause, like this:The
HAVINGclause will make MySQL to do another filtering pass on the query result (including any aggregate results) and then discards those records not matching theHAVINGclause.You can also have several conditions in the
HAVINGclause, like this: