Generate all possible combinations for Columns(cross join or Cartesian product)

in post-pandemic new world we can solve this with: =INDEX(FLATTEN(A2:A3&” “&TRANSPOSE(B2:B4))) to account for future expansion we can do: =INDEX(FLATTEN(FILTER(A2:A; A2:A<>””)&” “&TRANSPOSE(FILTER(B2:B; B2:B<>””)))) for 3 columns: =INDEX(FLATTEN(FLATTEN( FILTER(A2:A; A2:A<>””)&” “&TRANSPOSE( FILTER(B2:B; B2:B<>””)))&” “&TRANSPOSE( FILTER(C2:C; C2:C<>””)))) 4 columns: =INDEX(FLATTEN(FLATTEN(FLATTEN( FILTER(A2:A; A2:A<>””)&” “&TRANSPOSE( FILTER(B2:B; B2:B<>””)))&” “&TRANSPOSE( FILTER(C2:C; C2:C<>””)))&” “&TRANSPOSE( FILTER(D2:D; D2:D<>””)))) for more see: https://stackoverflow.com/a/74160711/5632629

cartesian product in pandas

In recent versions of Pandas (>= 1.2) this is built into merge so you can do: from pandas import DataFrame df1 = DataFrame({‘col1′:[1,2],’col2’:[3,4]}) df2 = DataFrame({‘col3′:[5,6]}) df1.merge(df2, how=’cross’) This is equivalent to the previous pandas < 1.2 answer but is easier to read. For pandas < 1.2: If you have a key that is repeated … Read more

CROSS JOIN vs INNER JOIN in SQL

Here is the best example of Cross Join and Inner Join. Consider the following tables TABLE : Teacher x————————x | TchrId | TeacherName | x———-|————-x | T1 | Mary | | T2 | Jim | x————————x TABLE : Student x————————————–x | StudId | TchrId | StudentName | x———-|————-|————-x | S1 | T1 | Vineeth | … Read more

SQL Server: What is the difference between CROSS JOIN and FULL OUTER JOIN?

A cross join produces a cartesian product between the two tables, returning all possible combinations of all rows. It has no on clause because you’re just joining everything to everything. A full outer join is a combination of a left outer and right outer join. It returns all rows in both tables that match the … Read more