M
M
moem2018-03-05 09:09:03
SQL
moem, 2018-03-05 09:09:03

How to set SQL query with aggregation from several tables?

Hello. Please tell me how to make a request.
Given:
- table main (id, ...);
- table first (id, id_main, ...) associated with main as many to one;
- table second (id, id_main, ...) associated with main as many to one.
It is required to receive a response of the form:
main.id, count(first.id_main), count(second.id_main).
At me both count all time are multiplied.
Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konstantin Tsvetkov, 2018-03-05
@tsklab

Use subqueries to count the number.

I
ISE73, 2018-03-05
@ISE73

Take out counts in subqueries.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question