In this paper, we introduce a new problem termed query reverse engineering (QRE). Given a database $$D$$ D and a result table $$T$$ T —the output of some known or unknown query $$Q$$ Q on $$D$$ D —the goal of QRE is to reverse-engineer a query $$Q'$$ Q ′ such that the output of query $$Q'$$ Q ′ on database $$D$$ D (denoted by $$Q'(D)$$ Q ′ ( D ) ) is equal to $$T$$ T (i.e., $$Q(D)$$ Q ( D ) ). The QRE problem has useful applications in database usability, data analysis, and data security. In this work, we propose a data-driven approach, TALOS for Tree-based classifier with At Least One Semantics, that is based on a novel dynamic data classification formulation and extend the approach to efficiently support the three key dimensions of the QRE problem: whether the input query is known/unknown, supporting different query fragments, and supporting multiple database versions.