C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » SQL Server »

Query Suggestion


Posted Date: 20 Aug 2008      Posted By: Sankararaman      Member Level: Silver     Points: 1   Responses: 4



Hello friends

I am having 3 tables as employee table, department table and employeedepartment tables

in the employee table I have empid and empName and in the department table I have depid and departmentName and in the empdepartment table I store empid and deptid.

Now in the emp table the value sare

1 A
2 B
3 C
In the department table the values are

1 X
2 Y
3 Z

In the employee department table I have values
dep id, empid
1 2
1 2

Now, I have to list the names of employees whose department is not allocated yet.

The values are A & C it is obvious and I have written the query as follows which gives me result


select distinct empname from emp,dept,empdept where dept.depid <> empdept.depid and
emp.empid <> empdept.empid;

But, can any one suggest me a better query?

Please help me

My advance thanks





Responses

Author: pradipta    20 Aug 2008Member Level: GoldRating: 2 out of 52 out of 5     Points: 2

You can try the following query

select empname from emp where empid in (select empid from empdept)



Author: pradipta    20 Aug 2008Member Level: GoldRating: 2 out of 52 out of 5     Points: 2

Sorry Please ignore my presvious reply.the query shoiuld be


select empname from emp where empid not in (select empid from empdept)



Author: Sankararaman    20 Aug 2008Member Level: SilverRating: 2 out of 52 out of 5     Points: 1

Hello Friends

I want this query without USING NOT IN. Please help me


My Advance thanks



Author: Ramdas Singh Baghel    21 Aug 2008Member Level: GoldRating: 2 out of 52 out of 5     Points: 0

Your are sick man.


Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : conversion of windows authentication to sql server login
Previous : Stored Procedure - Value check
Return to Discussion Forum
Post New Message
Category: SQL Server

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use