Answer the question
In order to leave comments, you need to log in
How to build sql query?
There is a sites table with id and name fields and a reviews table with value and id_site fields
For one value from the sites table there can be several values from the reviews table, you must not just link these two tables, but sum all the values from the reviews table for the corresponding value from the sites
table For example:
sites
id - name
-----------
1 - site.ru
2 - site.com
-----------------
reviews
id_site - value
-- ---------------
1 - 3
1 - 4
The result should be:
1 - site.ru - 7
2 - site.com - null
How to get such a result with one sql query?
Answer the question
In order to leave comments, you need to log in
SELECT s.name, sum(r.value) FROM reviews as r
LEFT JOIN sites as s ON s.id = r.site_id
GROUP BY r.id_site
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question