In this paper, we introduce a new problem termed query reverse engineering (QRE). Given a database D and a result table T—the output of some known or unknown query Q on D—the goal of QRE is to reverse-engineer a query Q′ such that the output of query Q′ on database D (denoted by Q′(D)) is equal to T (i.e., 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.