i have 2 sql queries each query made with join
1st sql query gives me 105 record which is active project
2nd sql query gives me 577 record which is past projects
i want to show this above 105 and 577 record in a pie chart number of active and past project should be seen in pie chart
how to make count of each query and put in in 1 query


Rajanikant HawaldarRank #110 · 20.2K reputationPosted Apr 15, 2019, 11:31 PM EDT
Abhishek SainiRank #202 · 11.9K reputationPosted Apr 16, 2019, 2:00 AM EDT
Naresh BeniwalRank #365 · 6.8K reputationPosted Nov 17, 2022, 12:40 PM EST
https://ubiq.co/database-blog/how-to-get-multiple-counts-with-single-query-in-mysql/
Rajesh GamiRank #30 · 41.5K reputationPosted Nov 18, 2022, 6:55 AM EST
Hello Subin
Try below query (Please set your fields based on your table)
Suppose your table name : ProjectDetal
Fields (Name, Technology, LeadId, IsActive, etc..
SELECT count(*) AS TotalProjectCount, sum(case when IsActive= 1 then 1 else 0 end) AS ActiveProjectCount, sum(case when IsActive= 0 then 1 else 0 end) AS InActiveProjectCount FROM ProjectDetailI hope this is work for you
Jignesh KumarRank #91 · 22.9K reputationPosted Nov 17, 2022, 11:01 PM EST
Hello Thomas,
You can do like below query,
SELECT ( SELECT COUNT(ProjectId) FROM Project where isActive=1 ) AS ActiveProject, ( SELECT COUNT(ProjectId) FROM Project where isActive=0 ) AS PastProjectSachin SinghRank #66 · 26.2K reputationPosted Nov 19, 2022, 4:15 AM EST
As per your description, you have two Select statements and you just need the count of each in a single select statement , am i correct?
Then
Declare @count1 int, @count2 int; set @count1= (select count(*) from table --your first query) set @count2= (select count(*) from table --your 2nd query); select @count1 As ActiveProjectCount,@count2 as PastProjectCount;