Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

MySQL failing to process Join Query with group by clause

Select deaths.County_Name as County, 
       max(cases.Cumulative_cases) as Cases, 
       max(deaths.Total_Deaths) as Deaths,
           max(deaths.Population2019) as Population2019
From pennsylvaniadeathsbycounty deaths
Join pennsylvaniacasesbycounty cases
    on deaths.County_Name = cases.Jurisdiction
group by County;

I get the following error: Error Code: 2013. Lost connection to MySQL server during query

The Jurisddiction and County_Name columns are identical between the two tables. I want to get a table that displays each counties deaths an cases as well as the the populations of each county. When I run the query it just loads for a while then returns the above error.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The query is timing out most likely, you could try union all instead of joining like this

select County,
       SUM(Cases) Cases,
       SUM(Deaths) Deaths,
       SUM(Population2019) Population2019
from(
Select deaths.County_Name as County, 
       0 as Cases, 
       deaths.Total_Deaths as Deaths,
       deaths.Population2019 as Population2019
From pennsylvaniadeathsbycounty deaths
union all
Select cases.Jurisdiction as County, 
       cases.Cumulative_cases as Cases, 
       0 as Deaths,
       0 as Population2019
From pennsylvaniacasesbycounty cases) a
group by County
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading