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
 General SQL Server Forums
 New to SQL Server Programming
 Joining two tables

Author  Topic 

rebeka.six
Starting Member

2 Posts

Posted - 2008-11-22 : 09:51:26
I need help with joining these two tables:

Table1

idx idy
---------
one 1
two 2
tree 3


Table2

idy u
-------
1 a
2 b
3 c
4 d
5 e
6 f

I want to show rows from the Table1 that have idx=one joined with all the rows from Table2.
So, I want to join these two tables so that Table1.idy=Table2.idy and Table1.idx=one
The result table should look like this.

Result table:

idx idy u
--------------
one 1 a
NULL 2 b
NULL 3 c
NULL 4 d
NULL 5 e
NULL 6 f

Can anyone help me with this?
Thanks.
Rebeka

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-11-22 : 10:01:52
select t1.idx,t2.idy,t2.u
from table2 t2
left outer join table1 t1.
on t2.idy = t1.idy
and t1.idx= 'one'
Go to Top of Page
   

- Advertisement -