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)
 Join question with identical tables

Author  Topic 

o9z
Starting Member

23 Posts

Posted - 2011-08-11 : 11:45:46
Table 1 = Company A Employee Info
Table 2 = Company A Pay Info
Table 3 = Company B Employee Info
Table 4 = Company B Pay Info

I need to pull ALL employees names from Table 1 and Table 3 and pull all pay info from Table2 and table 4. These need to be joined to show just to fields. Employee Name from the employee info tables and Pay Rate from the pay info tables.

What is the proper join to do this? My results weren't what I expected.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-11 : 11:51:49
you need to do like

SELECT t1.EmpName,t2.PayRate
FROM Table1 t1
JOIN Table2 t2
ON t2.EmpID = t1.EmpID
UNION ALL
SELECT t3.EmpName,t4.PayRate
FROM Table3 t3
JOIN Table4 t4
ON t4.EmpID = t3.EmpID


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -