We address the problem of answering conjunctive queries over knowledge bases, specified by sets of first-order sentences called tuple-generating dependencies (TGDs). This problem is highly relevant to query optimization, information integration, and ontological reasoning. We present a rewriting algorithm, inspired by resolution in Logic Programming, which is capable of dealing with an expressive class of TGDs, called sticky TGDs. Given a set of sticky TGDs and a conjunctive query, the algorithm produces a first-order query that can be then evaluated over the data, providing the correct answers. In this way, we establish that conjunctive query answering under sticky TGDs is in the highly tractable class ac0 in the data complexity.