diff --git a/ecrire/base/abstract_sql.php b/ecrire/base/abstract_sql.php
index d7b273f2b0c82e90c1c78ceb51c68ff60bcb1e0e..c41e800aef4b981e5ae71643d449f65c26a5f444 100644
--- a/ecrire/base/abstract_sql.php
+++ b/ecrire/base/abstract_sql.php
@@ -355,8 +355,12 @@ function sql_fetsel(
 function sql_getfetsel(
 		       $select, $from = array(), $where = array(), $groupby = array(), 
 	$orderby = array(), $limit = '', $having = array(), $serveur='', $option=true) {
+	if (preg_match('/\s+as\s+(\w+)$/i', $select, $c)) $id = $c[1];
+	elseif (!preg_match('/\W/', $select)) $id = $select;
+	else {$id = 'n'; $select .= ' AS n';}
 	$r = sql_fetsel($select, $from, $where,	$groupby, $orderby, $limit, $having, $serveur, $option!==false);
-	return $r ? $r[$select] : NULL;
+	if (!$r) return NULL;
+	return $r[$id]; 
 }
 
 // http://doc.spip.org/@sql_version
diff --git a/ecrire/exec/statistiques_repartition.php b/ecrire/exec/statistiques_repartition.php
index f02f05fb7791e2d89c539939d8fc188e732c3663..6563b186d75fe42daadc913b6312c20215a7db76 100644
--- a/ecrire/exec/statistiques_repartition.php
+++ b/ecrire/exec/statistiques_repartition.php
@@ -25,9 +25,7 @@ function enfants($id_parent, $critere){
 	while($row = sql_fetch($result)) {
 		$id_rubrique = $row['id_rubrique'];
 
-		$row2 = sql_fetsel("SUM(".$critere.") AS cnt", "spip_articles", "id_rubrique=$id_rubrique");
-
-		$visites = !$row2 ? 0 : $row2['cnt'];
+		$visites = intval(sql_getfetsel("SUM(".$critere.")", "spip_articles", "id_rubrique=$id_rubrique"));
 		$nombre_abs[$id_rubrique] = $visites;
 		$nombre_vis[$id_rubrique] = $visites;
 		$nombre += $visites + enfants($id_rubrique, $critere);
diff --git a/ecrire/inc/forum.php b/ecrire/inc/forum.php
index 5e5756b7d3cc8e3279855e06755cf4f34c0f35cb..a158b9652d0104a39d710bc7f7675ab55c9d3d31 100644
--- a/ecrire/inc/forum.php
+++ b/ecrire/inc/forum.php
@@ -19,10 +19,7 @@ function affiche_navigation_forum(&$query, $script, $args, $debut, $pas, $enplus
 	if (!$pas) $pas = 10;
 	if (!$enplus) $enplus = 100;
 
-	// A revoir: ceci n'est pas equivalent a sql_countsel
-	// a cause du GroupBy
-	$total = sql_count(sql_select($query['SELECT'], $query['FROM'], $query['WHERE'], $query['GROUP BY']));
-
+	$total = sql_countsel($query['FROM'], $query['WHERE'], $query['GROUP BY']);
 	// pas de navigation si tout tient
 	if ($total > $pas) {
 		if ($total <= $debut) $debut = $total-$pas;
diff --git a/ecrire/req/mysql.php b/ecrire/req/mysql.php
index 65dc9b745af32252d603746607fa15c1ed30cf55..d2ad5d06f242b9ff64b7e82f697a5936a2cfc3c4 100644
--- a/ecrire/req/mysql.php
+++ b/ecrire/req/mysql.php
@@ -490,7 +490,8 @@ function spip_mysql_fetch($r, $t='', $serveur='',$requeter=true) {
 function spip_mysql_countsel($from = array(), $where = array(),
 			     $groupby = '', $limit = '', $sousrequete = '', $having = array(), $serveur='',$requeter=true)
 {
-	$r = spip_mysql_select('COUNT(*)', $from, $where,$groupby, '', $limit,
+	$c = !$groupby ? '*' : ('DISTINCT ' . (is_string($groupby) ? $groupby : join(',', $groupby)));
+	$r = spip_mysql_select("COUNT($c)", $from, $where,'', '', $limit,
 			$having, $serveur, $requeter);
 	if (!$r OR !$requeter) return $r;
 	list($c) = mysql_fetch_array($r, MYSQL_NUM);
diff --git a/ecrire/req/pg.php b/ecrire/req/pg.php
index 91b62801007040430cc743347039e7e665cf1709..4f55c42c7b9ea301c39b26814be7ceff27d98775 100644
--- a/ecrire/req/pg.php
+++ b/ecrire/req/pg.php
@@ -539,8 +539,8 @@ function spip_pg_countsel($from = array(), $where = array(),
 			  $groupby=array(), $limit='', $sousrequete = '', 
 			  $having = array(), $serveur='',$requeter=true) 
 {
-	$r = spip_pg_select('COUNT(*)', $from, $where,
-			    $groupby, '', $limit, $having, $serveur, $requeter);
+	$c = !$groupby ? '*' : ('DISTINCT ' . (is_string($groupby) ? $groupby : join(',', $groupby)));
+	$r = spip_pg_select("COUNT($c)", $from, $where,'', '', $limit, $having, $serveur, $requeter);
 	if ($r && $requeter) list($r) = pg_fetch_array($r, NULL, PGSQL_NUM);
 	return $r;
 }
diff --git a/ecrire/req/sqlite_generique.php b/ecrire/req/sqlite_generique.php
index dfd7435f27d25f2222e9890833083dda587e8715..f6a7e73852b093297bd0cc1b484d5a50794acea3 100644
--- a/ecrire/req/sqlite_generique.php
+++ b/ecrire/req/sqlite_generique.php
@@ -323,7 +323,8 @@ function spip_sqlite_count($r, $serveur='',$requeter=true) {
 
 // http://doc.spip.org/@spip_sqlite_countsel
 function spip_sqlite_countsel($from = array(), $where = array(), $groupby = '', $limit = '', $sousrequete = '', $having = array(), $serveur='',$requeter=true) {
-	$r = spip_sqlite_select('COUNT(*)', $from, $where,$groupby, '', $limit,
+	$c = !$groupby ? '*' : ('DISTINCT ' . (is_string($groupby) ? $groupby : join(',', $groupby)));
+	$r = spip_sqlite_select("COUNT($c)", $from, $where,'', '', $limit,
 			$having, $serveur, $requeter);
 	
 	if ($r && $requeter) {