Chapter 5. Queries
Prev | The KNODA user's tutorial | Next

## Chapter 5. Queries

One of the reasons of having a database full of data is that you would like to extract that data using various criteria. There are 2 ways to create queries: Either you create it with a graphical user interface - called 'Query by example' - or you write your SQL code into an editor.

### Important

For all kinds of queries please keep the following in mind: If your column names contains non-ascii characters (e.g. German umlauts), or you need to delimit text, you have to use the following standard delimiters (independent from your SQL-server)

- textdelimiter: ' (quote)

- identifiers: " (doublequote)

This way identifier names will be case-sensitive and much more important SQL-server independent. It is recommended to always use these delimiters.

Example 5.1. Using query delimiters

    SELECT "my table"."my field" FROM "my table" WHERE "my field" > 'my search text'

## Query by example

First add the datasources with the help of the 'Add datasource'-button (the one with the small yellow '+'). The relation between the datasources can be created via drag&drop. Now you can add the columns that should be displayed in the result set. Conditions can be added in the rows starting with "Criteria". All conditions in the same row will be 'AND'-combined, different rows will be 'OR'-combined.

Now we want to add a calculated field. We want to display the age of the authors (the difference between the year of his birth and the year of his death). Leave the 'Table'-cell empty and add '"deathyear"-"birthyear"' in the "Fieldname"-cell. To have a better header for the result set, you can add 'age' into the 'Alias'-cell.

Figure 5.1. Query by example window

Relations between two datasources can be created with 'drag and drop'. Click on the field of interest of the first table and while holding down the mouse button move the cursor to the field of interest in the second table and release the mouse button. A dialog will appear that let you set all equivalent column names. To edit a relation double-click the relation line (best is to click it on the arrow).

Prev | Up | Next
Chapter 4. Tables - creating a new table | Home | SQL statements