The Query Builder allows you to define a subset of a table using a SQL-like WHERE clause and display the result in the main window. The query result then can be saved as a new vector layer.
Open the Query Builder by opening the Layer Properties and go to the General menu. Under Feature subset click on the [Query Builder] button to open the Query builder. For example, if you have a regions layer with a TYPE_2 field you could select only regions that are borough in the Provider specific filter expression box of the Query builder. Figure_attributes_2 shows an example of the Query builder populated with the regions.shp layer from the QGIS sample data. The Fields, Values and Operators sections help the user to construct the SQL-like query.
Figure Attributes 2:
The Fields list contains all attribute columns of the attribute table to be searched. To add an attribute column to the SQL where clause field, double click its name in the Fields list. Generally you can use the various fields, values and operators to construct the query or you can just type it into the SQL box.
The Values list lists the values of an attribute table. To list all possible values of an attribute, select the attribute in the Fields list and click the [all] button. To list the first 25 unique values of an attribute column, select the attribute column in the Fields list and click the [Sample] button. To add a value to the SQL where clause field, double click its name in the Values list.
The Operators section contains all usable operators. To add an operator to the SQL where clause field, click the appropriate button. Relational operators ( = , > , ...), string comparison operator (LIKE), logical operators (AND, OR, ...) are available.
The [Test] button shows a message box with the number of features satisfying the current query, which is usable in the process of query construction. The [Clear] button clears the text in the SQL where clause text field. The [OK] button closes the window and selects the features satisfying the query. The [Cancel] button closes the window without changing the current selection.
The selected features can be saved as any OGR supported vector format and also transformed into another Coordinate Reference System (CRS). Just open the right mouse menu of the layer and click on Save selection as ‣ to define the name of the output file, its format and CRS (see Section Map Legend). It is also possible to specify OGR creation options within the dialog.