SQLTeam.com | Weblogs | Forums

Columns from different tables


#1

I’m looking to write a sql statement that will pull three columns from three different tables side by side so I can compare them, any help would be appreciated.


#2
select t1.a, t1.b, t1.c, t2.a, t2.b,t2.c
from table1 t1
join table2 t2 on t1.? = t2.?

Where ? is a column the tables have in common


#3

Getting to know SQL new to this. The columns are common they are a list of employees , level 1, level 2 and level 3. I'm checking for names that I made have missed.


#4

so for the join you can write:

join table2 t2 where t1.level1 = t2.level1 and t1.level2 = t2.level2, -- etc


#5

Why would anyone ever place employees into separate tables based on level?


#6

To make it hard to pro/demote anyone?


#7

That would seem to be the case...


#8

@oldguy - It's not clear that you're actually trying to accomplish or what you're actually working with... I've got a gut feeling that you're working from a single Employee table and trying to sort individuals into their organizational levels... and that you're beating yourself up trying to do it manually. If that's the case, let us know, we can show you how to use a recursive CTE and have this done in a snap,

If you're really trying to organize your employee hierarchy structure by using separate tables for each level, you should really stop and reconsider that approach.