F
F
fedot13252016-04-08 12:24:09
PHP
fedot1325, 2016-04-08 12:24:09

How to count the number of rows separately in three different tables in one query?

Hello.
The following question arose, I have 3 tables:
track_open, track_link, track_like
They are almost the same in structure, each has an id, user_id, post_id.
I want to count how many total openings, how many likes and transitions each post I need (I want to set several post_id through IN () at once).
And at the same time get something like this:
+---------+--------+------+------+
| post_id | opens | likes | links |
+---------+------- +------+------+
| 55 | 5213 | 123 | 25 |
| 56 | 1263 | 55 | 14 |
+-------- +------- +------+------+
How to make a query correctly?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2016-04-08
@AlexListen

SELECT
(SELECT COUNT(*) FROM tabl_1) AS t1Count,
(SELECT COUNT(*) FROM tabl_2) AS t2Count,
(SELECT COUNT(*) FROM tabl_3) AS
t3Count

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question