We have three tables pictures , movies , stories . Each table has the same status columns, created_at .
status can be of three types: active , pending , deleted
It is necessary to receive in one request the number of lines created in the last hour and in the last 24 hours . Clearly, it should look something like this:
---------------------------------------------------- |Status |Pics1h|Pics24h|Mov1h|Mov24h|Stor1h|Stor24h| ---------------------------------------------------- |active | 12 | 30 | 8 | 14 | 20 | 31 | ---------------------------------------------------- |pending| 2 | 4 | 1 | 4 | 2 | 8 | ---------------------------------------------------- |deleted| 10 | 34 | 2 | 45 | 33 | 45 | ---------------------------------------------------- I can display one column, for example:
SELECT status, count(*) as `Pics1h` FROM pictures WHERE (created_at >= DATE_SUB(NOW(), INTERVAL 60 MINUTE)) GROUP BY status; How to get data from three tables, possibly with several queries, but as efficiently as possible?
COUNT(*)andCOUNT(field)are not the same thing. - root_x Povierennyy