 <p>if personnel_id!='' mean NOT NULL use personnel_id IS NOT NULL instead and having use numberpid > 1 so query after edited below </p> <pre><code>SELECT COUNT(DISTINCT personnel_id) AS numberpid FROM planning WHERE personnel_id IS NOT NULL GROUP BY personnel_id HAVING numberpid &gt; 1 </code></pre>