title: How to remove empty row of NULL fields from mysql query containing sum
body: <p>I have this following query which join multiple tables</p>
  
  <pre><code>SELECT targa,
  registrazioni.turno as turno,
  conduttori.nome as nome,
  conduttori.cognome as cognome,
  spese_importo,risparmio,km, SUM(spese.spese_importo) AS totspese
  FROM registrazioni LEFT JOIN conduttori
  ON id_conduttore=conduttori.id
  LEFT JOIN spese
  ON registrazioni.id=spese.id_registrazione
  WHERE dataora='$data';
  </code></pre>
  
  <p>when I added this SUM(spese.spese_importo), I started having a small issue, and even if the query shouldn't have for me any matching result, I obtain as result an empty row where every field is NULL.</p>
  
  <p>Of course if I remove that SUM from my query, it does work again and I don't have any rows as result of the query</p>
  
  <p>How could I solve it and check if there are results not null?</p>
  
  <p>I've tried via mysql to add the condition</p>
  
  <pre><code>WHERE targa IS NOT NULL
  </code></pre>
  
  <p>(targa is just one field I've randomly choosen between the different fields they are all NULL)</p>
  
  <p>but it didn't clear the row, and via php I was using the condition</p>
  
  <pre><code>mysqli_num_rows($result)==0
  </code></pre>
  
  <p>but now that I always have at least 1 row it doesn't work.</p>
  
  <p>any other ideas for checking it before fetching the rows?</p>