I have two tables Table A and Table B as listed below.
Table A -------- X Y Table -------- X Y
What is the SQL query to get the below output?
XX XY YX YY
Advertisement
Answer
This looks like a cross join
, to generate all possible combinations of rows between the two tables. Assuming a structure like tablea(col)
, tableb(col)
:
select a.col, b.col from tablea a cross join tableb b order by a.col, b.col
If you want to concatenate the results in a singe column:
select a.col || b.col as col from tablea a cross join tableb b order by a.col, b.col