PgAccess Tutorial

# PgAccess Tutorial - SELECT

## What is a query?

Query is the term for an SQL command which will perform an operation on a table. It is sometimes confusing to newcomers, as some of the operations seem to have nothing to do with querying in the common sense of asking. As we saw in the previous section, a query can simply copy records from an ASCII file to a table.

The PostgreSQL documentation has a complete list of queries that can be used. We'll start with the common task of selecting records with certain characteristics.

## Selecting records

Suppose that I want to know all of the references in the sample table psyref for which the word "alternative" appeared in the title.

By clicking Query, then New, a Query builder window will appear. Clicking in the area below the buttons will allow the user to enter an SQL query. The specification of the query must be exact or PostgreSQL will return an error message.

The query shown will SELECT those records from psyref that contain the word "alternative" anywhere in the title field. The '*' indicates that all of the fields are to be returned. You might only want to return, for instance, the author field if you were only interested in which authors had used that word in the title of their work.

At the right is the record that fulfils these conditions, displayed in the Table viewer. If you wanted to save this query for use again, clicking the Save query definition button will do so. You will then see altern listed under Queries when you return to the main window. By clicking the Save this query as a view tickbox in the Query builder, the result of your query will be saved as a View which you can access from Views in the main window. Click the Close button to leave the Query builder.

Back to index