Let's say I have 2 tables.
TableA only has one column and looks like this (it will always only have one column but the values in this column will change over time):
TableA
------
Column1:
A
G
T
R
Table B has many columns (but none of these columns will ever match a value from column1 of Table A). ie
TableB
------
Column1: Column2: Column3:
65 xyz fgdsg
97 tmkl sjg
184 soi trhd
I would like to be able to return the below result set in a query:
TabA.Column1: TabB.Column1: TabB.Column2: TabB.Column3:
------------- ------------ ------------ ----------
A 65 xyz fgdsg
A 97 tmkl sjg
A 184 soi trhd
G 65 xyz fgdsg
G 97 tmkl sjg
G 184 soi trhd
T 65 xyz fgdsg
T 97 tmkl sjg
T 184 soi trhd
R 65 xyz fgdsg
R 97 tmkl sjg
R 184 soi trhd
To accomplish this I thought of unioning Table开发者_Python百科B x times where x is the count from TableA but I don't think you can create x number of unions dynamically in SQL alone. I am only looking for a solution in SQL code (it may incorporate the use of pre-defined PL/SQL functions).
Just a CROSS JOIN doesn't work? A cross join results in the Cartesian product of the input sets.
SELECT * FROM TableA CROSS JOIN TableB
Happy coding
What you want is a cross join. Joining everything from table A to Table B.
SELECT * FROM TableA
CROSS JOIN TableB
精彩评论