Consulte http://dev.mysql.com/doc/ refman/5.0/en/counting-rows.html Então sua consulta seria SELECT session_id, COUNT(*) FROM gallery_list GROUP BY session_id