mardi 2 avril 2019

How can I join multiple tables on the same auto generated integer from one "table"?

I want to create a random selected cross joined table which auto increments its own id and joins on it.

Let's say my tables looking like this.

Person

Firstname, Lastname 

Hans      | Müller
Joachim   | Bugert

Address
City, Street, StreetNumber
Hamburg | Wandsbeckerstr. | 2
Berlin  | Konradstraße    | 13

Now I want to join the tables with a auto generated ID and they should be random selected.

The final table should look like this.

ID,Firstname,Lastname, City, Street, StreetNumber
1 |Hans|Bugert|Berlin|Wandsbeckerstr|2
2|Joachim|Müller|Hamburg|Konradstraße | 13

What I already tried or used:

Whit this I autogenerate the ID where I want to join the tables on.

select GENERATED_PERIOD_START as ID FROM SERIES_GENERATE_INTEGER(1,1,10)

The problem is cross join and inner join isnt working for me because it always joins everything with everything or its not joining on the same ID.

SELECT Person."Firstname", Person."Lastname", Address."City",Address."Street", Address."StreetNumber"

FROM 
(   select GENERATED_PERIOD_START as ID FROM SERIES_GENERATE_INTEGER(1,1,10)

) autoGenID
inner JOIN
(select "Firstname" ,"Lastname" FROM Person ORDER BY RAND()) Person

inner JOIN 
(select "City", "Street", "StreetNumber", FROM Address  ORDER BY RAND()) Address

JOIN ON autoGenID."ID"=?????

Here is my problem I cant just select random data and select that on my auto gernated ID.

Thanks for your help or idears how to solve this!




Aucun commentaire:

Enregistrer un commentaire