Graphing temp and humidity from MariaDB

As some of my other posts mentioned I am stepping my way through a smart home build. Currently I have Arduinos sending temp and humidity to MariaDB on my Pi. I am pulling it back into NR and graphing it. However I would like to only pull partial amounts of this back like the last 100 points. Right now I am using a select query.

msg.topic = "SELECT * FROM houseTable;"

return msg;

How do I select the last 100 entries in that table.

SELECT * FROM houseTable LIMIT 100 will probably give you the first 100 records.

SELECT * FROM houseTable ORDER BY key_field ASC LIMIT 100 will definitely give you the first 100 records.

SELECT * FROM houseTable ORDER BY key_field DESC LIMIT 100 will give you the last 100 records but in descending order.

SELECT * FROM (SELECT * FROM houseTable h ORDER BY h.key_field DESC limit 100) a ORDER BY a.key_field ASC should give you the last 100 records in ascending order.

That's how I learned to do it, there may well be simpler syntax available now (hmm, SQL, simpler syntax? Not likely!)

1 Like

Thanks, much appreciated! Still haven't had a chance to give it a try. Been BUSY!