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?
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.