-2

I'm trying to order the following results on reference. Using Order by and desc limit 100. Can someone help me where to place it.

$stm = $pdo->prepare("SELECT `reference`, SUM( `stockdifference` ) AS 'stockdifference'  
FROM `results1` 
WHERE `datum` BETWEEN '".$oldDate."' AND '".$newDate."' AND `reference` = '".$stm[0]."'");

2 Answers2

0

To order a sql query is simple.

Select *
FROM table
Where column=condition
ORDER BY column desc/asc
Limit
  • are you sure he is asking about the SQL syntax and not about how to write the PDO parameters? – Dragos Dec 08 '16 at 13:02
-1

try :

<?php 
$stm = $pdo->prepare("SELECT `reference`, SUM( `stockdifference` ) AS 'stockdifference'  
FROM `results1` 
WHERE `datum` BETWEEN '".$oldDate."' AND '".$newDate."' AND `reference` = '".$stm[0]."'
Order by 'your column',
'your column' desc,
limit 100

");
nimour pristou
  • 143
  • 1
  • 8