Databases may not always satisfy their integrity constraints (ICs). However, in most cases an important part of the data is still consistent with the ICs, and can still be retrieved through queries posed to the database. Consistent query answers are characterized as answers obtained from every minimally repaired and consistent version of the database. Database repairs can be specied as stable models of disjunctive logic programs. Consistent Query Answering (CQA) for first-order queries is translated into cautious reasoning under the stable models semantics. Using logic programs in a straightforward manner is usually inefficient. We develop optimized techniques to evaluate queries over inconsistent databases by using logic programs. We optimize the structure of programs, model computation, and evaluation of queries from them. Moreover, we propose the use of the well-founded semantics (WFS) as an alternative way to obtain consistent answers. The WFS has lower data complexity than the stable models semantics. We also extend the use of logic programs for retrieving consistent answers to aggregate queries, and we develop a repair semantics for Data Warehouses.