php - can i merge those 2 queries in one query -
hello can merge 2 queries in 1 query first query number of articles in database , second query sum of visits of article whats best method make 1 query
$stmt = $db->query('select * stories'); $story_count = $stmt->rowcount(); $stmt = $db->query("select sum(visits) stories"); $total_visits = $stmt->fetchcolumn();
try like
$stmt = $db->query('select count(*) total_cnt, sum(visits) total_visits stories');
then excute query,you result "total_cnt" , "total_visits"
Comments
Post a Comment