Home > Blockchain >  Oracle - Select multiple aliased rows from dual
Oracle - Select multiple aliased rows from dual

Time:11-16

In Oracle I want to select 2 columns with multiple rows:

Example:

name   Phone
----   -----
John   1234
Mary   4321

This doesn't work:

select
   'John' as name,
   'Mary' as name,
   '1234' as phone,
   '4321' as phone
from
   dual

CodePudding user response:

Union together two single-row queries:

select
   'John' as name,
   '1234' as phone
from
   dual
union all
select
   'Mary' as name,
   '4321' as phone
from
   dual
NAME PHONE
John 1234
Mary 4321

db<>fiddle

  • Related