I need to be able to generate run a query that will return the next value of ID on the following table:
CREATE TABLE animals (
id MEDIUMINT NOT NULL AUT
Have a look at MariaDBs SEQUENCE Engine. With it you can generate sequences as easy as
SELECT seq FROM seq_1_to_5;
+-----+
| seq |
+-----+
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
+-----+
Details here: https://mariadb.com/kb/en/mariadb/sequence/
With this you should be able to do something like
SELECT min(seq) as nextVal FROM seq_1_to_500
WHERE seq NOT IN (SELECT ID FROM customers)