 <p>You can use parameters only once in a query</p> <pre><code>$sql1="SELECT @rownum := @rownum + 1 Rank, q.* FROM (SELECT @rownum:=0) r,(SELECT * ,sum(`number of cases`) as tot, sum(`number of cases`) * 100 / t.s AS `% of total` FROM `myTable` CROSS JOIN (SELECT SUM(`number of cases`) AS s FROM `myTable` where `type`=:criteria and `condition`=:diagnosis) t where `type`=:criteria2 and `condition`=:diagnosis2 group by `name` order by `% of total` desc) q"; $stmt = $dbh-&gt;prepare($sql1); $stmt-&gt;execute(array(':criteria' =&gt; $search_crit, ':diagnosis' =&gt; $diagnosis, ':criteria2' =&gt; $search_crit, ':diagnosis2' =&gt; $diagnosis)); </code></pre>