SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 sql query help
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

pasumpon
Starting Member

1 Posts

Posted - 11/28/2012 :  08:58:39  Show Profile  Reply with Quote

table name : employee

it contain field name : emp_id

emp_id values 1,3,5,7,9,10

MY question is

if put condition in where statement like " where emp_id in ('1','2','3','4')" ( these values are i m inputing into the query)

my output should be emp_id 2,4


what query condition i need to put . plz help me



sunitabeck
Flowing Fount of Yak Knowledge

5155 Posts

Posted - 11/28/2012 :  09:12:03  Show Profile  Reply with Quote
Reverse the logic, for example:
SELECT * FROM 
( VALUES (1),(2),(3),(4)) t(emp_id)
WHERE NOT EXISTS
(SELECT * FROM Employee e WHERE e.emp_id = t.emp_id)
Go to Top of Page

sodeep
Flowing Fount of Yak Knowledge

USA
7174 Posts

Posted - 11/28/2012 :  10:38:32  Show Profile  Reply with Quote
Select E.Id from Employee E
Where emp_id in (1,2,3,4)
and NOT Exists
(Select * from Employee Where emp_id = E.emp_id)
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000