Javier del Saz
Javier del Saz

Reputation: 856

MySQL Field with custom values defined by user

I know yo can do: SELECT "javier" as names;

#  names
  ----- 
1 javier

There is any way to get a custom field with user defined values for each row? something like SELECT ("javier","piter", "mike"); And obtain:

#  names
   -----
1  javier
2  piter
3  mike

Upvotes: 1

Views: 845

Answers (1)

Vamsi Prabhala
Vamsi Prabhala

Reputation: 49260

select 'javier' as names
union all
select 'piter'
union all
select 'mike'
...

You can use union all.

If you need a column with auto rownumbers, you could do

select @rn := @rn+1 as `#`, names
from (
select 'javier' as names
union all
select 'piter'
union all
select 'mark') x,
(select @rn := 0) t

Upvotes: 2

Related Questions