You can specify certain criteria for the fields of a query to be retrieved from the database via a filter, so that when you build reports on the query, the returned results will be narrowed down. In addition, you can also apply sub-queries to a filter. You can type your filter criteria both in the format of a filter and a QBE (Query By Example). The overall conditions will include them both. Always click the SQL button to view your conditions and parse the query to ensure the syntax is valid.
The criteria panel in the lower part of the Query Editor window is for you to filter out some unnecessary records in a query. This filter is in the format of Query by Example (QBE).
When filtering with the QBE format, you are prompted to type the search criteria into a template resembling the data record. The advantage of query-by-example retrieval is that you don't need to learn a query language to frame a query. All the data fields are shown to you, and all you need to do is to enter the information that restricts the search to the required criteria. Any fields left blank, however, will match everything.
The columns and menus allow you to specifically define criteria for the fields in JReport Designer. For example, if a field is labeled REGION, and this field is a list of all 50 states in the United States. If you only want to see information from California (CA) and New York (NY), in the criteria menu, you can pick out CA and NY by placing their names in the column as seen below.

You just need to type in NY and CA. JReport Designer automatically places the ='xx' (equal sign and quotes) in the column for you. Below is a list of the syntax available:
Note that in an Oracle database, if you want to use a Date or DateTime type parameter or a specific date or time to filter the field of a query, you need to apply the to_date() or to_timestamp() function in the filter condition, for example:

Compared with QBE, the filter provides you with more flexibility with entering your conditions. The expression includes not only the DBField selected, but also formulas and parameters. You can also manually type in strings that are supported by the database.
To filter with the filter format, select Filter from the Query menu. The Search Condition dialog appears. See the dialog.
Specifying expressions:
The expressions are the main section of the filter. To place a criterion, follow the steps below:
to specify the field in the Expressions dialog.
to specify the value of how to filter the field in the Expressions dialog or input the value manually. You can also use sub-queries to narrow down the result with the Subquery tab.See also Dynamically filtering queries for additional information about how parameters can be used to filter queries dynamically.
Tip: You can make use of the symbols at the bottom of the Expressions dialog to modify the expression according to your requirements.
When filtering the fields of a query with the filter format, you are also enabled to use sub-queries to narrow down the result. The following are syntaxes that can be used in sub-queries.
Quantified predicate
A quantified predicate compares a value with a set of values.
expression----+- = --+- SOME --+-- ( subselect )
+- <> -+ ANY ---+
+- ! = --+ ALL ----+
+- < --+
+- > --+
+- <= --+
+- ! > --+
+- >= --+
+- ! < --+
The subselect must specify a single result column and can return any number of values, whether they are null or not.
SELECT qty FROM sales WHERE qty>= ALL (SELECT qty FROM sales)
SELECT BUYERID, ITEM FROM ANTIQUES WHERE PRICE != ANY (SELECT PRICE FROM ANTIQUES);EXISTS predicate
The EXISTS predicate tests for the existence of certain rows.
- [ NOT ] EXISTS--(subselect)
The subselect may specify any number of columns and,
SELECT DISTINCT pub_name FROM publishers WHERE EXISTS (SELECT * FROM titles WHERE pub_id = publishers.pub_id AND type = 'business')IN predicate
The IN predicate compares a value with a set of values.
expression----+-- [NOT] IN --+-- ( subselect )
In the subselect form, the subselect must identify a single result column and may return any number of values, whether null or not null.
SELECT distinct pub_name FROM publishers WHERE pub_id IN (SELECT pub_id FROM titles WHERE type = 'business')The following example explains how to apply a subquery when filtering a field:
beside the field text box. In the Expressions dialog, select the column Customers_Customer ID, then close the dialog.
beside the value text box. In the Expressions dialog, click the Subquery tab. Select an existing query in the catalog to be the subquery. If you want to edit the selected query, click the Edit Subquery button. To create a new subquery, click the New Subquery button.
Here, we create a new query named subin, add the table Orders, select the column Orders_Customer ID, and add a condition "Ship Via=Express Delivery" in the Search Condition dialog.
Now, the subquery subin will be applied to the filter when you build a report that uses the Customers_Customer ID column.
Notes:
To remove the parameter condition from a query if this happens, check Ignore Predicate If Parameter Value Is Null on the Query menu.