Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

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

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

Flowing Fount of Yak Knowledge

5155 Posts

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

Flowing Fount of Yak Knowledge

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  
 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.03 seconds. Powered By: Snitz Forums 2000