V
V
Vlad Chepel2016-02-11 17:38:28
MySQL
Vlad Chepel, 2016-02-11 17:38:28

How to do it in one request?

there are 3 requests, how do i turn them into one?
a) select countries.name, count(camps.id) from countries join camps on countries.id = camps.region_id
b) select regions.name, count(camps.id) from regions join camps on regions.id = camps.region_id
c) select cities.name, count(camps.id) from cities join camps on cities.id = camps.region_id

Answer the question

In order to leave comments, you need to log in

3 answer(s)
N
nozzy, 2016-02-11
@nozzy

select countries.name, regions.name, cities.name, count(camps.id) from camps 
inner join countries on countries.id = camps.region_id
inner join regions on regions.id = camps.region_id
inner join cities on cities.id = camps.region_id
group by countries.name, regions.name, cities.name

�
Петр, 2016-02-11
@petermzg

select 
  union all
select
  union all
select

X
xtender, 2016-02-20
@xtender

group by + rollup?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question