I have a table that changes name every day and I want to write a query that will "find" it and work on it without the need to change the name of the table in my query every day.
I can easily find it using a query like that
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME LIKE '%_TABLE_CONST_NAME' ORDER BY CREATED DESC LIMIT 1
This will return the table_name I want to query, eg: randomstring_TABLE_CONST_NAME
I tried using it like that but it didn't work (obviously) because it queries the result, not the table
SELECT * FROM (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME LIKE '%_TABLE_CONST_NAME' ORDER BY CREATED DESC LIMIT 1) table
And I would like it to evaluate the query result and query it as ``SELECT * FROM randomstring_TABLE_CONST_NAME table`
Any ideas? Thank you
A possible solution is writing a stored procedure that will find your table and query it.