Search code examples
sqlsalesforcesalesforce-marketing-cloud

Join unrelated table with unequal rows


I would like to join Table A, Table B, and Table C as the expected result in the attached image.

Image Link


Solution

  • You can enumerate the rows and use that for joining . . . which might be what you want:

    select ab.*, c.*
    from (select a.*, b.*,   -- really list out the columns you want
                 row_number() over (order by accountid) as seqnum
          from a join
               b
               on a.accountid = b.accountid
         ) ab join
         (select c.*, row_number() over (order by code) as seqnum
          from c
         ) c
         on ab.seqnum = c.seqnum