943,829 Members | Top Members by Rank

Ad:
  • MS SQL Discussion Thread
  • Marked Solved
  • Views: 1141
  • MS SQL RSS
Nov 22nd, 2008
0

Joining two tables

Expand Post »
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

Could someone help me with this?
Thanks.
Rebeka
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rebeka.six is offline Offline
2 posts
since Nov 2008
Nov 23rd, 2008
0

Re: Joining two tables

i don't see how you are expecting idx = NULL for 2-6, when you have both entries for idy in both tables

are you sure this is what you are wanting?
Reputation Points: 133
Solved Threads: 141
Veteran Poster
dickersonka is offline Offline
1,162 posts
since Aug 2008
Nov 24th, 2008
0

Re: Joining two tables

Try this command:
MS SQL Syntax (Toggle Plain Text)
  1. SELECT T1.idx, T2.idy, T2.u
  2. FROM Table1 T1 RIGHT JOIN Table2 T2 ON
  3. T1.idy = T2.Idy AND T1.idx = 'one'
Reputation Points: 10
Solved Threads: 13
Light Poster
huangzhi is offline Offline
48 posts
since Feb 2008
Nov 24th, 2008
0

Re: Joining two tables

Hi,

Works perfectly!
Thanks,

Rebeka
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rebeka.six is offline Offline
2 posts
since Nov 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MS SQL Forum Timeline: Transfer of data
Next Thread in MS SQL Forum Timeline: Need Advice please





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC