Note that as the OP presents it, the id column in table2 is a foreign key to table1.
alter table table2 add column rank int;
-- better reviews have lower ranks
alter table table2 constraint table2idrank unique( id, rank) ;
-- ranks are unique within a product
-- note, ranks must also be consecutive
create view min_rank_review as
select id, min(rank) as rank
from table2
group by id;
create view product_review_pivot as
select a.product, b.review as r1, c.review as r2, d.review as r3, e.review as r4
from
table1 a left outer join table2 b on (a.id = b.id)
join min_rank_review m on (b.id = m.id and b.rank = m.rank)
left outer join table2 c on (c.id = b.id and c.rank + 1 = b.rank)
left outer join table2 d on (d.id = c.id and d.rank + 1 = c.rank)
left outer join table2 e on (e.id = f.id and e.rank + 1 = d.rank);
select * from product_review_pivot;
On edit: I suppose the down-mods are because this didn't work. But replace left outer join min_rank_review m on (b.id = m.id and b.rank = m.rank)
with join min_rank_review m on (b.id = m.id and b.rank = m.rank)
(and make a few other minor corrections) and it works.
Sorry, my office mate wanted to go home and woudn't give me time to proof-read it. :)
With the following data inserted:
insert into table1 ( product ) values ('a'), ('b');
insert into table2(id, review, rank) values
(1, 'r1', 1 ), (1, 'r2', 2), (1, 'r3', 3 ),
(1, 'r4', 4), (1, 'r5', 5 ), (2, 'rr2', 1);
I get the following ouput (in MySQL 5):
mysql> select * from product_review_pivot;
+---------+------+------+------+------+
| product | r1 | r2 | r3 | r4 |
+---------+------+------+------+------+
| a | r1 | r2 | r3 | r4 |
| b | rr2 | NULL | NULL | NULL |
+---------+------+------+------+------+
(The solution for non-sequential ranks is left as an exercise.)