RSS Forums RSS

Joining two tables

Please support our MS SQL advertiser: Programming Forums
Thread Solved
Reply
Posts: 2
Reputation: rebeka.six is an unknown quantity at this point 
Solved Threads: 0
rebeka.six rebeka.six is offline Offline
Newbie Poster

Joining two tables

  #1  
Nov 22nd, 2008
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
AddThis Social Bookmark Button
Reply With Quote  
Posts: 1,157
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 133
dickersonka dickersonka is offline Offline
Veteran Poster

Re: Joining two tables

  #2  
Nov 23rd, 2008
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?
Custom Application & Software Development
www.houseshark.net
Reply With Quote  
Posts: 30
Reputation: huangzhi is an unknown quantity at this point 
Solved Threads: 10
huangzhi huangzhi is offline Offline
Light Poster

Re: Joining two tables

  #3  
Nov 24th, 2008
Try this command:
select	T1.idx, T2.idy, T2.u
  from	Table1 T1 right join Table2 T2 on
	T1.idy = T2.Idy and T1.idx = 'one'
Hence Wijaya
www.ex-Soft.tk
Reply With Quote  
Posts: 2
Reputation: rebeka.six is an unknown quantity at this point 
Solved Threads: 0
rebeka.six rebeka.six is offline Offline
Newbie Poster

Re: Joining two tables

  #4  
Nov 24th, 2008
Hi,

Works perfectly!
Thanks,

Rebeka
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Similar Threads
Other Threads in the MS SQL Forum
Views: 748 | Replies: 3 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 2:22 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC