From 4d4f563ca60a0dffe6a29c010bb6d833bb2abb91 Mon Sep 17 00:00:00 2001 From: Olivier Hallot Date: Sat, 14 May 2022 15:21:05 -0300 Subject: [PATCH] Revisit Base Query page Change-Id: I74ab17b065f0dcd516ba7a80ee08c4d11f84aa49 Reviewed-on: https://gerrit.libreoffice.org/c/help/+/134330 Tested-by: Jenkins Reviewed-by: Olivier Hallot --- source/text/sdatabase/02010100.xhp | 41 ++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/source/text/sdatabase/02010100.xhp b/source/text/sdatabase/02010100.xhp index 85233468ad..39e2e60e31 100644 --- a/source/text/sdatabase/02010100.xhp +++ b/source/text/sdatabase/02010100.xhp @@ -167,9 +167,11 @@

Alias

Specifies an alias. This alias will be listed in the query instead of the field name. This makes it possible to use user-defined column labels. For example, if the data field is named PtNo and, instead of that name, you would like to have PartNum appear in the query, enter PartNum as the alias. In a SQL statement, aliases are defined as follows: -SELECT column AS alias FROM table. +SELECT column AS alias FROM table. For example: -SELECT "PtNo" AS "PartNum" FROM "Parts" + +SELECT "PtNo" AS "PartNum" FROM "Parts" +

Table

@@ -289,16 +291,22 @@ You can also enter function calls directly into the SQL statement. The syntax is: -SELECT FUNCTION(column) FROM table. +SELECT FUNCTION(column) FROM table. For example, the function call in SQL for calculating a sum is: -SELECT SUM("Price") FROM "Article". + +SELECT SUM("Price") FROM "Article". + Except for the Group function, the above functions are called Aggregate functions. These are functions that calculate data to create summaries from the results. Additional functions that are not listed in the list box might be also possible. These depend on the specific database engine in use and on the current functionality provided by the Base driver used to connect to that database engine. To use other functions not listed in the list box, you must enter them manually under Field. You can also assign aliases to function calls. If you do not want to display the query string in the column header, enter a desired substitute name under Alias. The corresponding function in an SQL statement is: -SELECT FUNCTION() AS alias FROM table +SELECT FUNCTION() AS alias FROM table +
Example: -SELECT COUNT(*) AS count FROM "Item" +
+ +SELECT COUNT(*) AS count FROM "Item" + If you run such a function, you cannot insert any additional columns for the query other than as an argument in a "Group" function. Examples In the following example, a query is run through two tables: an "Item" table with the "Item_No" field and a "Suppliers" table with the "Supplier_Name" field. In addition, both tables have a common field name "Supplier_No." @@ -685,11 +693,16 @@ Like Escape Sequence: {escape 'escape-character'} -Example: select * from Item where ItemName like 'The *%' {escape '*'} + + +SELECT * FROM Item WHERE ItemName LIKE 'The *%' {escape '*'} + The example will give you all of the entries where the item name begins with 'The *'. This means that you can also search for characters that would otherwise be interpreted as placeholders, such as *, ?, _, % or the period. Outer Join Escape Sequence: {oj outer-join} -Example: select Article.* from {oj item LEFT OUTER JOIN orders ON item.no=orders.ANR} - + + +SELECT Article.* FROM {oj item LEFT OUTER JOIN orders ON item.no=orders.ANR} +

Querying text fields

To query the content of a text field, you must put the expression between single quotes. The distinction between uppercase and lowercase letters depends on the database in use. LIKE, by definition, is case-sensitive (though some databases don't interpret this strictly). @@ -755,8 +768,14 @@ -Example: select {d '1999-12-31'} from world.years -Example: select * from mytable where years='1999-12-31' + + +SELECT {d '1999-12-31'} FROM world.years + + + +SELECT * FROM mytable WHERE years='1999-12-31' + All date expressions (date literals) must be enclosed with single quotation marks. (Consult the reference for the particular database and connector you are using for more details.)

Querying Yes/No fields