简体   繁体   中英

MySQL Dual table Join Dual table

Is there a way to JOIN fields from the dummy DUAL table in MySQL?

Say I have a

SELECT 1 as n1 FROM DUAL

n1
--
 1

and a

SELECT 2 as n2 FROM DUAL

n2
--
 2

Can I join both selects with a Join in some kind of query as...

SELECT 1 as n1 FROM DUAL JOIN (SELECT 2 as n2 FROM DUAL) ON 1=1

?

Here's one way...

Select t1.n1, t2.n2 
from (select 1 as n1) t1 
CROSS JOIN (Select 2 as n2) t2;

Here's another

Select t1.n1, t2.n2 
from (select 1 as n1, 'A' as ID) t1 
INNER JOIN (Select 2 as n2, 'A' as ID) t2
  on T1.Id = T2.ID;

and you could just do

Select 1 as n1, 2 as n2

but I assume there's a reason you need the joins.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM