SQL Simple Join with two tables, but one is random

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

declare @Table_A as table(
  [column_A] varchar(256)
);

insert into @Table_A values
('[email protected]'),
('[email protected]'),
('[email protected]'),
('[email protected]');



declare @Table_B as table(
  [column_A] varchar(1000)
);
insert into @Table_B values
('ABCD1234'),
('ABCD5678'),
('ABCD9876'),
('ABCD5432');

;with cte as(
    select [rn] = row_number() over(
        order by [Column_A]
    ), *
    from @Table_A
),
cte2 as(
    select [rn] = row_number() over(
        order by [Column_A]
    ), *
    from @Table_B
)
select t1.[Column_A] as [Email_Id], t2.[Column_A] as [Coupon]
from cte t1
join cte2 t2
on t1.rn = t2.rn;

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results