2
$query="Select distinct * from voucher_payment LEFT Join vouchers ON voucher_payment.voucher_id = vouchers.voucher_id LEFT JOIN payment_details ON voucher_payment.payment_id= payment_details.payment_id where paid_amount > 0";

$result = pg_query($conn,$query);

<th>File Name</th>
<th>Date Recieved</th>




</tr>
</thead>
<?php 

while($row = pg_fetch_array($result))
{
$servicedate=$row['service_dos']; 
$code= $row['cpt_code'];
$servicedate= substr($row['service_dos'],0,4) . "-". substr($row['service_dos'],4,2). "-". substr($row['service_dos'],6) ;

$query2="Select * from charge LEFT Join payment ON charge.charge_id = payment.charge_id where charge.cpt_code NOT LIKE '" .$code  . "' AND charge.charge_treatment_date != '" .$servicedate  . "'";
$result2 = pg_query($conn2,$query2); 
$row2= pg_fetch_array($result2);


?>

<tbody>


<tr>

<td><?php echo $row['file_name']; ?></td>
<td><?php echo $row['parsing_date']; ?></td>

The outcome are:

File name                Date
---------               --------
2943875897               2016-07-08
2943875897               2016-07-08
2943875897               2016-07-08
2943875897               2016-07-08

And so on, I put distinct but still the same results just different names, can anyone tell me what seems to be the issue? I also wanted to GROUP BY thinking it would help but it didn't.

Serena
  • 45
  • 8
  • What column did you group by? `GROUP BY file_name` should absolutely work. – Jan Holas Oct 06 '16 at 12:09
  • I did and I got this error: ERROR: column "vouchers.voucher_id" must appear in the GROUP BY clause or be used in an aggregate function – Serena Oct 06 '16 at 12:11
  • still same result @kerv – Serena Oct 06 '16 at 12:15
  • Oh, I didn't notice postgresql tag and assumed MySQL. Check this question then: http://stackoverflow.com/questions/19601948/must-appear-in-the-group-by-clause-or-be-used-in-an-aggregate-function – Jan Holas Oct 06 '16 at 12:16

0 Answers0