Query multiple tables I store time stamps in four different tables and I like to query mysql to give me total amount of timestamps for a given day.

SELECT
  time_stamp AS Tid,
  Count(time_stamp) as Tot 
FROM (select time_stamp from ink_norr union all select time_stamp from ink_syd) x
GROUP BY DAY(time_stamp) 
ORDER BY 1;


Gives me this

+------------------------+-------+
| Tid                    | Tot   |
+------------------------+-------+
| 0000-00-00 00:00:00.00 |     1 |
| 2018-05-31 17:59:29.97 |    16 |
| 2018-06-01 01:13:18.72 |  9540 |
| 2018-06-03 01:25:05.51 | 10390 |
| ...                    |   ... |
+------------------------+-------+


But I am rather after something like this

+------------------------+-------+-------+-------+
| Tid                    | Tot   | Syd   | Norr  |
+------------------------+-------+-------+-------+
| 0000-00-00 00:00:00.00 |     1 |     1 |     0 | 
| 2018-05-31 17:59:29.97 |    16 |     8 |     8 |
| 2018-06-01 01:13:18.72 |  9540 |   540 |  9000 |
| 2018-06-03 01:25:05.51 | 10390 |    89 | 10301 |
| ...                    |   ... |    .. |     . |
+------------------------+-------+-------+-------+
Try this:

SELECT
  DAY(time_stamp) AS Day,
  COUNT(time_stamp) as Tot,
  SUM(CASE WHEN origin = 's' THEN 1 ELSE 0 END) as Syd,
  SUM(CASE WHEN origin = 'n' THEN 1 ELSE 0 END) as Norr
FROM (select time_stamp, 'n' as origin from ink_norr union all select time_stamp, 's' as origin from ink_syd) x
GROUP BY DAY(time_stamp) 
ORDER BY 1;