MySQL – Select Count Without Join

join;MySQL

I'm using MySQL. I have three tables, and in every table, I have a time column.

With a single query I want to count the number of rows that are between two given dates.

I have no need with a connection between the tables (although they are related), so join is not necessary.

Is it possible?

Failed attempt #1

SELECT
  COUNT(a.time),
  COUNT(b.time),
  COUNT(c.time)
FROM
  tbl1 AS a,
  tbl2 AS b,
  tbl3 AS c
WHERE
  a.time BETWEEN '2018-03-07 18:32:55' AND '2018-03-07 20:46:55'
AND
  b.time BETWEEN '2018-03-07 18:32:55' AND '2018-03-07 18:46:55'
AND
  c.time BETWEEN '2018-03-07 18:32:55' AND '2018-03-07 18:46:55' ;

Best Answer

If you want it pivoted:

SELECT 
    ( SELECT COUNT(*) FROM  tbl1
         WHERE time BETWEEN '2018-03-07 18:32:55'
                        AND '2018-03-07 20:46:55' ) AS a
    ( SELECT COUNT(*) FROM  tbl2
         WHERE time BETWEEN '2018-03-07 18:32:55'
                        AND '2018-03-07 20:46:55' ) AS b
    ( SELECT COUNT(*) FROM  tbl3
         WHERE time BETWEEN '2018-03-07 18:32:55'
                        AND '2018-03-07 20:46:55' ) AS c
;

which gives something like

  a   b   c
 10   3  14