Kexi/Handbook/Building Simple Databases/Designing Database Queries: Difference between revisions
Marked this version for translation |
Splitting lists into smaller units |
||
Line 13: | Line 13: | ||
<!--T:5--> | <!--T:5--> | ||
# Create a new empty query by selecting <menuchoice>Insert->Query...</menuchoice> from the menubar. The design window will appear. The window is split into two areas: query relationships at the top and query columns below. | # Create a new empty query by selecting <menuchoice>Insert->Query...</menuchoice> from the menubar. The design window will appear. The window is split into two areas: query relationships at the top and query columns below. </translate> | ||
# Select the table persons in the drop down list '''Table:''' located at the top of the window and click the <menuchoice>Add</menuchoice> button. A graphical representation of the table will appear in the relations area. Do the same for the phone_numbers table to insert it too, as in the figure below. | <translate> | ||
# Select the table persons in the drop down list '''Table:''' located at the top of the window and click the <menuchoice>Add</menuchoice> button. A graphical representation of the table will appear in the relations area. Do the same for the phone_numbers table to insert it too, as in the figure below. </translate> | |||
<translate> | |||
# Add query relationship using mouse drag & drop technique: click the field id in the table persons table, drag it and drop into the person field of the '''''phone_numbers''''' table. This will join both fields by creating a new relationship. | # Add query relationship using mouse drag & drop technique: click the field id in the table persons table, drag it and drop into the person field of the '''''phone_numbers''''' table. This will join both fields by creating a new relationship. | ||
# Double-click the name field in the persons table, to add the field as a query column. In a similar way, add '''''surname''''', '''''street''''', '''''house_number''''', '''''city''''' fields from the persons table and phone from the '''''phone_numbers''''' table. | # Double-click the name field in the persons table, to add the field as a query column. In a similar way, add '''''surname''''', '''''street''''', '''''house_number''''', '''''city''''' fields from the persons table and phone from the '''''phone_numbers''''' table. </translate> | ||
# Query design is now ready for testing. Click the <menuchoice>Switch to data view</menuchoice> button on the toolbar, to switch from design to viewing the data provided as query results. | <translate> | ||
# Query design is now ready for testing. Click the <menuchoice>Switch to data view</menuchoice> button on the toolbar, to switch from design to viewing the data provided as query results.</translate> | |||
<translate> | |||
# Save the query design for later use by clicking the Save button on the toolbar. You can also use <menuchoice>File->Save</menuchoice> from the menubar or press the <keycap>Ctrl+S</keycap> keys. Because the query design has not been saved yet, you will be asked to specify a name for it. Enter '''''Contacts''''' text in the caption field and click the <menuchoice>OK</menuchoice> button. | # Save the query design for later use by clicking the Save button on the toolbar. You can also use <menuchoice>File->Save</menuchoice> from the menubar or press the <keycap>Ctrl+S</keycap> keys. Because the query design has not been saved yet, you will be asked to specify a name for it. Enter '''''Contacts''''' text in the caption field and click the <menuchoice>OK</menuchoice> button. | ||
Revision as of 12:06, 18 December 2011
Designing Database Queries
A database's primary purpose is to store and help extract information you are looking for. Unlike databases written on a paper sheets, Kexi database allows you to specify more search criteria. Results are returned faster even for large data sets. All this is a power of databases, however to be able to perform effective queries in your database, you need to learn how to tell the database what you are looking for.
With database queries you can limit data coming from a table to a predefined set of rows and columns as well as dynamically join data coming from multiple tables.
To see how queries work in practice you will create a contacts query joining data from two tables: persons and phone_numbers (designed here and filled with data here).
- Create a new empty query by selecting from the menubar. The design window will appear. The window is split into two areas: query relationships at the top and query columns below.
- Select the table persons in the drop down list Table: located at the top of the window and click the button. A graphical representation of the table will appear in the relations area. Do the same for the phone_numbers table to insert it too, as in the figure below.
- Add query relationship using mouse drag & drop technique: click the field id in the table persons table, drag it and drop into the person field of the phone_numbers table. This will join both fields by creating a new relationship.
- Double-click the name field in the persons table, to add the field as a query column. In a similar way, add surname, street, house_number, city fields from the persons table and phone from the phone_numbers table.
- Query design is now ready for testing. Click the button on the toolbar, to switch from design to viewing the data provided as query results.
- Save the query design for later use by clicking the Save button on the toolbar. You can also use Ctrl+S keys. Because the query design has not been saved yet, you will be asked to specify a name for it. Enter Contacts text in the caption field and click the button. from the menubar or press the