Show the location codes for all documents.
select location_code from document_locations
Also show their locations.
select t2.location_name, t1.location_code from document_locations as t1 join ref_locations as t2 on t1.location_code = t2.location_code
How many documents come from each location?
select t2.location_name, t1.location_code, count(*) from document_locations as t1 join ref_locations as t2 on t1.location_code = t2.location_code group by t1.location_code
Which location has the fewest?
select t2.location_name, t1.location_code from document_locations as t1 join ref_locations as t2 on t1.location_code = t2.location_code group by t1.location_code order by count(*) asc limit 1