tags:

views:

79

answers:

7

If i have two tables that have nothing in common

I want to do a select as follows:

column from table1, column from table 2

How do I do it?

+1  A: 
SELECT table1.column, table2.column 
FROM table1, table2 

gives you the cartesian product. Not really sure if that's what you need though?

Martin Smith
+1  A: 

This seems to work in SQL Server assuming you want the Cartesian Product

SELECT A.Column, B.Column
FROM TableA A, TableB B
Jacob G
+1  A: 

Meaning, you want the cartesian product of the two tables?

Look at doing a CROSS JOIN.

Phil Sandler
+1  A: 

If both tables have a single row this isn't a big issue:

SELET ( SELECT COLUMN1 FROM TABLE1 ) AS COL1, ( SELECT COLUMN1 FROM TABLE2 ) AS COL2;

See the other answers for the cartesian product and this link which is weary of them:

http://www.rampant-books.com/t_hpsdba_77_cartesian_join_operations.htm

Nissan Fan
actually this is not working
I__
+2  A: 

Try a UNION ALL

SELECT columnA FROM table1 UNION ALL SELECT columnB from table2

Evan Carroll
+1  A: 

If you're not concerned with the columns appears beside each other AND the data types are compatible, you can use UNION.

SELECT columnA FROM table1
UNION
SELECT columnB FROM table2
Barry Brown
Clarification on this technique ... using UNION keyword will remove duplicates from the results. If you want duplicates, then use UNION ALL instead, which concatenates the two table result sets.
SnapJag
+1  A: 

Well, you can't really unless both tables have have zero or one row then you can use Jacob G's answer.

Otherwise, 3 rows in one and 2 rows in another will give the Cartesian product = 6 rows.

If you don't want the cross/Cartesian product then you're asking for a jagged recordset which is not possible. How should rows from one table relate to a row in the other table?

If they are truly unrelated, it's 2 separate calls...

gbn