Ahh, I see your dilema now, and yeah, I doubt there is a way to do it without a subquery. Fortunately though, the [man]implode[/man] function can save you from having to bastardize your server with a loop of queries.
$sql = "SELECT u.user_id,
count(ue.event) AS cnt
FROM user u
LEFT JOIN user_event ue
ON u.user_id = ue.user_id
WHERE ue.event = 'SOMETHING'
GROUP BY u.user_id
HAVING cnt = 0";
$res = mysql_query($sql);
if(mysql_num_rows($res) > 0) { # make sure we have results
$users = array(); # blank array to store user id's
while($row = mysql_fetch_array($res))
$users[] = $row['user_id']; # add user_id to the array
# Now perform one queries against all of the ID's
$sql = "SELECT user_id,
event
FROM user_event
WHERE user_id IN ('".implode("', '", $users)."')";
$rez = mysql_query($sql);
}
else
echo 'No rows returned';
Though, for the sake of testing, you could try a natural join, then a left join. Something like this:
$sql = "SELECT u.user_id,
uu.event,
count(ue.event) AS cnt
FROM user u, user_event uu
LEFT JOIN user_event ue
ON u.user_id = ue.user_id
WHERE u.user_id = uu.user_id
AND ue.event = 'SOMETHING'
GROUP BY u.user_id, uu.event
HAVING cnt = 0";
I actually sort of doubt that query will work as-is, but the idea is to first just join the tables to get id and event together, then perform the left join for the count. More just a hairball idea I had, no real idea if it would work or not :bemused: