Page 1 sur 1

Requête pour recuperer derniére valeur NOT NULL

Posté : 17 déc. 2023, 20:15
par FredD
Bonjour,
Je souhaite récupérer dans une BDD la derniére valeur non null de la colonne pm25

J'ai essayé avec cette requête mais j'ai toujours un retour d'erreur
Fatal error: Uncaught mysqli_sql_exception: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'WHERE pm25 IS NOT NULL' at line 1 in /storage/ssd4/987/21478987/public_html/esp-database.php:126 Stack trace: #0 /storage/ssd4/987/21478987/public_html/esp-database.php(126): mysqli->query() #1 /storage/ssd4/987/21478987/public_html/esp-weather-station.php(102): getLastReadingsnotnull() #2 {main} thrown in /storage/ssd4/987/21478987/public_html/esp-database.php on line 126
voici la requête

Code : Tout sélectionner

$sql = "SELECT pm25 FROM SensorData ORDER BY id desc limit 10 WHERE pm25 IS NOT NULL";

Re: Requête pour recuperer derniére valeur NOT NULL

Posté : 17 déc. 2023, 21:09
par or 1
il faut respecter l'ordre : where order by limit

Re: Requête pour recuperer derniére valeur NOT NULL

Posté : 18 déc. 2023, 10:57
par FredD
il faut respecter l'ordre : where order by limit
Je pensais que l'ordre était ODER by limit et ensuite WHERE