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 2005 Forums
 Transact-SQL (2005)
 join two tables without relations

Author  Topic 

jdub_92
Starting Member

13 Posts

Posted - 2008-10-18 : 03:44:17
Hi,

I want to join two tables, but there is no relation between them,

table1
vendorid CHAR(5),
companyname VARCHAR(30),
repfname VARCHAR(20),
replname VARCHAR(20),
referredby CHAR(5)


table2
Col1 int,
Col2 varchar(10),
Col3 datetime

how can i join them?, is it possible?


thanks,

jwill

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-18 : 04:12:20
its possible. but you will get result as cartesian product of them unless you've a linking field b/w them .use like below

SELECT *
FROM table1
CROSS JOIN table2


not sure if you're lookinmg for this
Go to Top of Page

malaytech2008
Yak Posting Veteran

95 Posts

Posted - 2008-10-18 : 23:30:37
Joining two tables without relation is meaningless.
Even if joining two tables it results a cartesian product of two tables.


malay
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-19 : 02:53:13
quote:
Originally posted by malaytech2008

Joining two tables without relation is meaningless.Even if joining two tables it results a cartesian product of two tables.


malay


Not always. what if you just want all combinations of values from both table. Consider case when one table contain month details and other day details. you may take cross join with them while generating a calendar table. such cases it do make sense.
Go to Top of Page

jdub_92
Starting Member

13 Posts

Posted - 2008-10-19 : 06:23:00
actually what i want is to know all the columns data type,what data type is available also in the other table,.

by cross joining i can be able to know it,.

what i want to do now is seperate columns that are not in the other table or same data type.,

sample scenario

table1
vendorid CHAR(5),
companyname VARCHAR(30),
repfname VARCHAR(20),
replname VARCHAR(20),
referredby CHAR(5)


table2
Col1 int,
Col2 varchar(10),
Col3 datetime


result 1:

Col2 varchar(10), companyname,repfname,replname = match data type

result 2:

Col1 int, Col3 datetime, vendorid, referredby char(5) = without match




syntax:

SELECT *
FROM table1
CROSS JOIN table2

problem now is how to achieve those result..how can i seperate those?


jwill
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-19 : 06:47:02
nope. you cant match datatypes using cross join. it takes only data from tables. for datatype matching, you need to make use of catalog view INFORMATION_SCHEMA.COLUMNS. It contain data type information of each column in tables of a db.
Go to Top of Page
   

- Advertisement -