Fetch Reattempt and Hold Date count in efficient way I am using 4 queries to get below 4 values , like this i need to use about 14 queries , Is there any way to reduce queries ?



&lt;?php
echo " " . date("Y-m-d")." ";
echo "Reattempt : "." ";

$sql =

"SELECT 
 COUNT(*) as count FROM orders
 WHERE DATE(reattemptdate) = CURDATE() 
 ";
$results = $db_handle-&gt;runSelectQuery($sql); 
$numrowsresult =$results[0]['count'];  
echo $numrowsresult;

echo " "." Hold : ";

$sql =

"SELECT 
 COUNT(*) as count FROM orders
 WHERE DATE(holddate) = CURDATE() 
 ";
$results = $db_handle-&gt;runSelectQuery($sql); 
$numrowsresult =$results[0]['count'];  
echo $numrowsresult;
echo "&lt;br&gt;";
?&gt;

&lt;?php
echo date("Y-m-d",mktime(0, 0, 0, date("m"), date("d")-1,date("Y")))." ";
echo "Reattempt : "." ";

$sql =

"SELECT 
 COUNT(*) as count FROM orders
 WHERE DATE(reattemptdate) = DATE(NOW() - INTERVAL 1 DAY) 
 ";
$results = $db_handle-&gt;runSelectQuery($sql); 
$numrowsresult =$results[0]['count'];  
echo $numrowsresult;

echo " "." Hold : ";

$sql =

"SELECT 
 COUNT(*) as count FROM orders
 WHERE DATE(holddate) = DATE(NOW() - INTERVAL 1 DAY) 
 ";
$results = $db_handle-&gt;runSelectQuery($sql); 
$numrowsresult =$results[0]['count'];  
echo $numrowsresult;



?&gt;
You can create one query and select all elements. For example:

select sum(case when DATE(reattemptdate) = CURDATE() THEN 1 ELSE 0 END) as reattemptdate,
       sum(case when DATE(holddate) = CURDATE() THEN 1 ELSE 0 END) as holddate,
       sum(case when DATE(reattemptdate) = DATE(NOW() - INTERVAL 1 DAY) THEN 1 ELSE 0 END) as prev_reattemptdate,
       sum(case when DATE(holddate) = DATE(NOW() - INTERVAL 1 DAY) THEN 1 ELSE 0 END) as prev_holddate
from orders;


php:

$results = $db_handle-&gt;runSelectQuery($sql); 
$reattemptdate =$results[0]['reattemptdate'];  
$holddate =$results[0]['holddate'];
$prevReattemptdate =$results[0]['prev_reattemptdate'];
$prevHolddate =$results[0]['prev_holddate'];
// display counters
echo $reattemptdate;
echo $holddate;
echo $prevReattemptdate;
echo $prevHolddate;