Max
Max

Reputation: 17

How to select a row multiple times with different value attached to each one?

I'm trying to select all rows 3 times with different value attached to each one of them, for example:

MyTable:

Name
_____
Tom
John

Result:

Name   MyValue
_____  _______
Tom    First
Tom    Second
Tom    Third
John   First
John   Second
John   Third

Anyone knows how to do it with MySQL?

Upvotes: 0

Views: 33

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269783

You can use cross join:

select t.name, x.which
from t cross join
     (select 'First' as which union all
      select 'Second' as which union all
      select 'Third' as which
     ) x
  

Upvotes: 1

Related Questions