# Queries

Relational databases typically contain many rows of data, with each row constituting a separate record. Most relational database queries retrieve only a portion of the records contained in a table. The WHERE clause qualifies the query command statement to limit the data to specific records from the tables.

Queries are a higher-level object in a catalog. Its concept is similar to that in the database. The working objects a query can select include tables/views (DBFields), formulas or summaries, and parameters, and the tables/views it can select from are the mapped tables/views defined in a JReport catalog. In this way, a query is independent from the raw database. You can use queries to view, change and analyze data in different ways, and JReport can help you with the building of various professional reports based on queries. When making a query, you can place criteria or restrictions on the data to extract only the required data from the database. For example, instead of having to view all the customers of your company, you can view just the customers from Japan. To do this, you specify conditions that limit the results to the records with Country field = "Japan".

JReport Designer provides you with an interactive query designer - the Query Editor, to build any queries as you like. It also enables you to build queries using the pre-join feature.

In addition, JReport Designer provides you with the Data Manager which allows you to control the data retrieval of your queries, including the number of rows to be displayed and the duration required for the retrieval. It can also keep access information from previous runs of a query (including imported SQL, stored procedure and UDS which function as queries).

The following topics describe queries:

- Creating a query
- Using pre-joins in queries
- Editing a query
- Previewing a query
- Creating and modifying a union query
- Locking queries
- Developing reports from queries
- Dynamic queries
- Query modifiers
- Cached query results
- Data Manager

See an example: The SampleComponents catalog, included with JReport Designer, contains reports that have examples of how queries could be used in a report. For the query example, open `<install_root>\Demo\Reports\SampleComponents\Query.cls`.