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 Two tables

Author  Topic 

coagulance
Yak Posting Veteran

78 Posts

Posted - 2009-12-09 : 05:04:49
Can any one one suggest , how to join two tables (without common columns) ie.. without the ON Criteria and also get distinct values

Table_X
VALUE DIMENSION
200 299
300 122
200 144
100 123

Table_Y
VALUE DIMENSION
600 599
600 522
400 164
300 153

Result should be:
X_Value Y_Value
100 300
200 400
300 600

Thanks



khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-12-09 : 05:09:51
can you explain how does the required result comes about ?

Oh looks like the requirement get more complicated at http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=136821


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

coagulance
Yak Posting Veteran

78 Posts

Posted - 2009-12-09 : 05:17:43
It just merges two different columns of two different tables and sorts them in asc order.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-12-09 : 09:16:06
[code]
select x.value, y.value
from
(
select Value, row_no = row_number() over (order by Value)
from Table_X
) x
inner join
(
select Value, row_no = row_number() over (order by Value)
from Table_Y
) y on x.row_no = y.row_no
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -