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

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Column Difference

Author  Topic 

Shadab Shah
Starting Member

23 Posts

Posted - 2012-07-30 : 00:27:31
Suppose i have a table as
Employee (Empid,EmpName,DeptId,ManId)

And then another table as
Department (DeptId,DeptName,ManId)

And now i want to perform the operation as (Employee - Department ) And the output i want is (EmpId,Empname,DeptName).

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-07-30 : 00:34:06
you use INNER JOIN on column DeptId

SELECT e.EmpId, e.Empname, d.DeptName
FROM Employee e INNER JOIN Department d ON e.DeptId = d.DeptId



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

Shadab Shah
Starting Member

23 Posts

Posted - 2012-07-30 : 00:46:32
I dont want records. In the above example just to make reader understand my problem i had given a sample. In practical there may be 20-30 columns in my table. The output that i am expecting is just as EmpId EmpName DeptName (No records).
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-07-30 : 00:58:02
quote:
Originally posted by Shadab Shah

I dont want records. In the above example just to make reader understand my problem i had given a sample. In practical there may be 20-30 columns in my table. The output that i am expecting is just as EmpId EmpName DeptName (No records).



Can you illustrate with an example ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

Shadab Shah
Starting Member

23 Posts

Posted - 2012-07-30 : 01:29:07
Hi. The output which i am looking should look like EmpId EmpName DeptName. thats it. Nothing more. The query should eliminate empid and manid because they are common in both the table.
Go to Top of Page
   

- Advertisement -