Now I need another query that will return the opposite of this. Web Accounts that are not in a security group (tblWebAccountGroup.Web_Account_Group_Name_ID!= var). Sounds simple to me and possible using an SQL query. At present I've done such queries in PHP by writing two queries and doing a data comparison and return what is different between the two queries. As I'm sure you realize this is a major amount of coding to do this manually. How can I do this using SQL? Any help would be greatly appreciated.
BTW, I'm using IIS v5.0.2195.3649 with PHP v4.2.3 and MSSQL Server 2000 (v8.00.760 Intel X86). If you need any table schemas or other information please let me know.
$szQry = "SELECT tblWebAccounts.People_ID, viewPeople.First_Name, viewPeople.Last_Name
FROM tblWebAccounts, viewPeople, tblWebAccountGroup
WHERE tblWebAccountGroup.Web_Account_Group_Name_ID=$_POST[nSecurityGroup]
AND tblWebAccounts.People_ID=viewPeople.People_ID
AND tblWebAccounts.Web_Account_ID=tblWebAccountGroup.Web_Account_ID
ORDER BY viewPeople.First_Name, viewPeople.Last_Name";
i.e.
where tblWebAccountGroup.Web_Account_Group_Name_ID=$_POST[nSecurityGroup]
is users from security group
and where tblWebAccountGroup.Web_Account_Group_Name_ID<>$_POST[nSecurityGroup]
is users not included into security group
:)
in sql expressions not equal sign is <>.
What is need to know.That's all:)
Do you see what I mean?
SELECT DISTINCT tblWebAccounts.Web_Account_ID, viewPeople.First_Name, viewPeople.Last_Name
FROM tblWebAccounts LEFT OUTER JOIN tblWebAccountGroup ON tblWebAccounts.Web_Account_ID=tblWebAccountGroup.Web_Account_ID, viewPeople
WHERE tblWebAccounts.People_ID=viewPeople.People_ID
AND tblWebAccountGroup.Web_Account_Group_Name_ID<>$_POST[nSecurityGroup]
ORDER BY viewPeople.First_Name, viewPeople.Last_Name
select * from table
where user not in (select user from table
where user = 'blah')
and to combine the two queries:
select * from table
where user = 'blah'
union
select * from table
where user not in (select user from table
where user = 'blah'
Obviously this is an over-simplification of your query, but may work.
Scott Geiger