The Query Builder allows you to define a subset of a table and display it as a layer in QGIS. It can currently only be used with PostGIS layers. For example, if you have a towns layer with a population field you could select only larger towns by entering population > 100000 in the SQL box of the query builder. Figure 17 shows an example of the query builder populated with data from a PostGIS layer with attributes stored in PostgreSQL.
The query builder lists the layer's database fields in the list box on the left. You can get a sample of the data contained in the highlighted field by clicking on thebutton. This retrieves the first 25 distinct values for the field from the database. To get a list of all possible values for a field, click on the button. To add a selected field or value to the query, double-click on it. You can use the various buttons to construct the query or you can just type it into the SQL box.
To test a query, click on thebutton. This will return a count of the number of records that will be included in the layer. When satisfied with the query, click . The SQL for the where clause will be shown in the SQL column of the layer list.
Tip xx Changing the Layer Definition
You can change the layer definition after it is loaded by altering the SQL query used to define the layer. To do this, open the vector sec:vectorprops for more information.dialog by double-clicking on the layer in the legend and click on the button on the tab. See Section