Minor point.
You don't need the "users" table in your sub-query. The user_id is already in the user_groups table, so there is no point to join the two tables. Just use this:
Code: Select all
$query= "SELECT *
FROM phpbb_users
WHERE user_id IN
(
SELECT ug.user_id
FROM phpbb_user_group AS ug
WHERE ug.group_id = 233
)
AND user_id NOT IN
(
SELECT ug.user_id
FROM phpbb_user_group AS ug
WHERE ug.group_id = 226
)
ORDER BY
username";
BTW, I assume you're not using MySQL, as I believe sub-queries are not supported until version 5. And if you're using a database that supports the MINUS or EXCEPT operation (check your documentation) try this; it's faster, and much more convenient:
Code: Select all
$query= "
SELECT ug.user_id
FROM phpbb_user_group AS ug
WHERE ug.group_id = 233
MINUS
SELECT ug.user_id
FROM phpbb_user_group AS ug
WHERE ug.group_id = 226 ";
That gives you a set of user_id values, and you can then process each one as desired. 8)