SQL4X, a powerful language for simultaneously querying both relational and XML databases, is presented. SQL4X queries can create both relations and XML documents as results. Thus, SQL4X can be thought of as an integration language. In order to allow easy inte- gration of XML documents with varied structures, SQL4X uses exible semantics. SQL4X is also a powerful query language. It can express quan- ti cation, negation, aggregation, grouping and path expressions. Datalog4x and Tree-Datalog4x , extensions of Datalog, are de ned as el- egant abstract models for SQL4X queries. Query containment is char- acterized for many common classes of SQL4X queries; for example, the class of conjunctive Datalog4x queries and the class of unions of such queries. Equivalence of Datalog4x queries under bag-set semantics is also characterized. A suÆcient condition for containment of Tree-Datalog4x queries is presented. This condition is shown to be complete for a large class of common queries.