Help With SQL Query

Help With SQL Query

Post by Stuart Sha » Tue, 10 Jun 2003 01:54:31



Hello All:

I have the following SQL Query

SELECT UserID,Name From Users

-- Users --
ID  Name
4   Test 1
5   Test 2
6   Test 3
7   Test 4
9   Test 5

I have a Restricted Users  Table

-- RestrictedUsers --
ID
5
7

I need a query that will list all users that are not in the restricted Users
Table

Which would be

4   Test 1
6   Test 3
9   Test 5

Thanks
Stuart

 
 
 

Help With SQL Query

Post by John Gilso » Tue, 10 Jun 2003 01:57:05



> Hello All:

> I have the following SQL Query

> SELECT UserID,Name From Users

> -- Users --
> ID  Name
> 4   Test 1
> 5   Test 2
> 6   Test 3
> 7   Test 4
> 9   Test 5

> I have a Restricted Users  Table

> -- RestrictedUsers --
> ID
> 5
> 7

> I need a query that will list all users that are not in the restricted Users
> Table

> Which would be

> 4   Test 1
> 6   Test 3
> 9   Test 5

> Thanks
> Stuart

SELECT *
FROM Users AS U
WHERE NOT EXISTS (SELECT *
                                       FROM RestrictedUsers
                                       WHERE U.UserID = ID)

Regards,
jag

 
 
 

Help With SQL Query

Post by Anith Se » Tue, 10 Jun 2003 05:09:51


Do:

SELECT *
  FROM Users
 WHERE Id NOT IN (SELECT t1.id
                    FROM RestrictedUsers t1)

--
- Anith

 
 
 

1. REQ: Help with SQL query on SQL 7

Hi

Can somebody assist me with the following query (posted below).  What I want
to do is perform the select statement with another qualifying statement that
returns only rows where the clg_log_cr_date is no older than 24 hours (ie
created within the last 24 hours).  The field clg_log_cr_date is a
smalldatetime.

Many thanks

Jeff

SELECT [clg_log].clg_logno AS "Log Number ",[cust_id] AS "Customer ",
[clg_genarea] AS "General Area ",
[clg_log_cr_date] AS "Creation Date ", [clg_owner] AS "Allocated to ",
[clg_nextact] AS "Next Action ", [clg_log_text] "Log Text"  FROM
[clg_log],[custagent]
WHERE
[custagent].cust_pointer=[clg_log].clg_custid AND
[clg_log].clg_log_rank='1' AND
[clg_log].clg_log_closed IS NULL
order by clg_log_cr_date

2. Question regarding ADO with NT Services

3. SQL Experts: Help with SQL query!!

4. Another Stored Procedure Question

5. Looking for Help with SQL Query in SQL Server 7.0

6. Listbox Control Question

7. Looking for help with SQL query in SQL SERVER 7.0

8. Error Opening Dts

9. Need help with SQL query

10. Need help on SQL query

11. Help with SQL query

12. Help with Sql Query

13. Help with SQL Query