Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL UNION: How to get data in two columns

Tags:

mysql

union

I have this SQL:

SELECT COUNT(*) as "With Gold"  FROM user_accounts_gold WHERE level = 6
UNION
SELECT COUNT(*) as "No Gold"    FROM user_accounts_bronze WHERE level = 6

At the moment this outputs:

| With Gold |
-------------
| 17734     |
| 2388      |

Is there a way to get this to output like so:

| With Gold | No Gold |
----------------------
| 17734     | 2388    |

Thanks

like image 990
modusTollens Avatar asked Sep 06 '25 03:09

modusTollens


1 Answers

Do a CROSS JOIN instead:

select * from
(SELECT COUNT(*) as "With Gold"  FROM user_accounts_gold WHERE level = 6) ug
CROSS JOIN
(SELECT COUNT(*) as "No Gold"    FROM user_accounts_bronze WHERE level = 6) ub
like image 128
jarlh Avatar answered Sep 07 '25 17:09

jarlh