Select all right-hand rows for each left-hand row of an SQL row .. HELP!

I'm currently looking for a Select statement that will do this.

|------Apples------| 
 |--id--|
 - 1   
 - 16
 - 23
 - 42

|------Oranges------| 
 |--id--|
 - a   
 - b
 - c

*SELECT STATEMENT*

|------Fruit Cocktail------| 

|--AppleID--|--OrangeID--|
   1              a
   1              b
   1              c
   16             a
   16             b
   16             c

etc...

So basically for each column on the left, select this and each right column

Thanks Daniel

+3
source share
3 answers

This is a simple cross join.

SELECT * FROM Apples, Oranges;

or

SELECT * FROM Apples CROSS JOIN Oranges;
+5
source
SELECT  *
FROM    Apples
CROSS JOIN
        Oranges

or, using the implicit join syntax, simply:

SELECT  *
FROM    Apples, Oranges
+5
source

Thanks guys!

The Boss Answered me for this simulation:

Select A.Apple,P.Peach From 
(
Select 1 As Apple
Union
Select 2 As Apple
Union
Select 3 As Apple
Union
Select 4 As Apple
Union
Select 5 As Apple
Union
Select 6 As Apple
) A
Cross Join
(
Select 'a' As Peach
Union
Select 'b'
Union
Select 'c'
Union
Select 'd'
Union
Select 'e'
) P
0
source

Source: https://habr.com/ru/post/1771690/


All Articles