David Bentzon-Ehlers David Bentzon-Ehlers - 4 months ago 15
SQL Question

How to split multiple select statements into columns

I want a way to split multiple

SELECT
statements into columns. Let me demonstrate what I mean with an example. Say I have these two statements:

SELECT COUNT(id) FROM tableA;
and
SELECT COUNT(id) FROM tableB
.

How can I, in the same query, put the
COUNT
s into two columns?

Answer

Try this:

SELECT (SELECT COUNT(id) FROM tableA) AS count1, 
       (SELECT COUNT(id) FROM tableB) AS count2