Ok, cool.. slowly getting somewhere now 😃
What I'm actually trying to do is make an advanced search option, where my script compiles a query and runs just one at the end. So far, it's like 50% working.. but I'm just building it up slowly, making sure it works as I go along..
Below is an example of a query that's working (where a username and a group is selected.. works fine, returning just the one result for each user, unlike the case underneath it.)
SELECT tms_users.id AS user_id, tms_users.user AS user_name, tms_users.level AS user_level, tms_users.login_suspend AS user_suspend
FROM tms_users, tms_user_group_members
WHERE tms_users.user LIKE '%Admin%'
AND tms_user_group_members.group_id =2
AND tms_user_group_members.user_id = tms_users.id
ORDER BY user ASC
However.. below is the sql to search for users that aren't in a group. It works to some extent, however returns a repeated row in the query result which repeats the same number as the records in the users table itself.. for each member that doesn't have a group..
So at the moment, I have 8 users in the database, 2 don't have a group. These 2 are returned sucessfully, but 8 times each! How can I stop this from happening with the below SQL?
SELECT tms_users.id AS user_id, tms_users.user AS user_name, tms_users.level AS user_level, tms_users.login_suspend AS user_suspend
FROM tms_users, tms_user_group_members
WHERE NOT
EXISTS (
SELECT tms_users.id
FROM tms_user_group_members
WHERE tms_user_group_members.user_id = tms_users.id
)
ORDER BY user ASC
Thank you VERY much for the help, I am learning quite a bit from this.. but still not sure where to advance to each time..