## Creating a query

To create a query in a catalog, follow the steps below:

1. In JReport Designer, open the required catalog, then do either of the following:
   - In the Catalog Browser, expand the data source in which you want to create the query, right-click the Queries node and select Add Query from the shortcut menu.
   - Click File > New > Query on the menu bar, specify the data source in which the query will be created, then click OK.
2. In the Input Query Name dialog, give a name for the query and click OK. The Query Editor window appears. See the window.

3. On the Query menu, click Add Table to add tables to the query.
4. Check the columns you want in each table. To select all, click *.
5. Join the tables added to the query as required.

   Based on the Auto Join options that are selected in the Query Editor category of the Options dialog, JReport will join the tables automatically. However, if the pre-join feature is enabled for the data source connection where the query is created, the auto join settings will not take effect, instead, JReport applies the pre-joins to the added tables. You can also add more joins among these tables according to your requirements.

6. Create filters on the query according to your requirement.
7. Add some computed columns and formula fields to the query if required.
8. Select Apply from the Query menu to save the query.

When a query has been added to a catalog, you can further edit it to suit your requirements.

Note: Normally, a query returns all the records that match its search criteria without considering whether there are duplicated ones. You can decide to get only one copy for each record by checking Select Distinct on the Query menu. When this option is enabled, SQL SELECT statements are treated as SELECT DISTINCT statements. The query will search for identical records and ensures to return them only once instead of returning duplicate records from the database.