php - Join Two Different Table -


i tried subtracting 2 different table same "pocde" column. have stated code below, doesn't work me. idea?

$result = mysql_query("     select          productlist.*,          sum(rreturn.total)-sum(rreturn.total) totals,          sum(rsales.tax)-sum(rreturn.tax) tax     productlist     left join rsales on rsales.pcode = productlist.pcode     left join rreturn on rreturn.pcode = productlist.pcode     group pcode     order total asc");      while($row = mysql_fetch_array($result)) {             echo '<tr>';             echo '<td style = "background-image:url(images/buts1.png)">'.($row['totals'].'</td>';                echo '<td style = "background-image:url(images/buts1.png)">'.($row['tax'].'</td>';                           echo '</tr>';     } 

you can't query because of group by. change query that:

 select pl.*, plagg.totals, plagg.tax productlist pl inner join (     select          productlist.pcode,          sum(rreturn.total)-sum(rreturn.total) totals,          sum(rsales.tax)-sum(rreturn.tax) tax      productlist     left join rsales on rsales.pcode = productlist.pcode     left join rreturn on rreturn.pcode = productlist.pcode     group productlist.pcode ) plagg on (plagg.pcode = pl.pcode) 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -