Skip to content

Add domain models and review OQL documentation #9914

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ Clauses must be presented in the following order, but can be left out if they ar

The `UNION` clause defies the usual order presented above. It will be presented in a [Union Clause](#oql-union) section at the end.

The domain model used in the various examples is shown below:

{{< figure src="/attachments/refguide/modeling/domain-model/oql/oql-clauses-domain-model.png" >}}

## `SELECT` Clause {#select}

The `SELECT` clause specifies which entity attributes or other specified data must be retrieved. The clause returns all the requested values of objects which match the `SELECT` clause.
Expand Down Expand Up @@ -111,15 +115,15 @@ The following query returns all attributes of objects of `Sales.Request` that ar
```
SELECT Sales.Request/*
FROM Sales.Customer
JOIN Sales.Customer/Sales.Customer_Request/Sales.Request
JOIN Sales.Customer/Sales.Request_Customer/Sales.Request
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was back to front naming?

```

The following query is equivalent to the previous one, but it uses table aliases

```
SELECT Req/*
FROM Sales.Customer Cust
JOIN Cust/Sales.Customer_Request/Sales.Request Req
JOIN Cust/Sales.Request_Customer/Sales.Request Req
```

### Selecting Distinct Values with `DISTINCT` {#distinct}
Expand Down Expand Up @@ -978,7 +982,7 @@ In the example below `Sales.Customer` object for Jim Elk does not have any assoc
```sql
SELECT LastName
FROM Sales.Customer
ORDER BY Sales.Customer/Sales.Customer_Request/Sales.Request/Number
ORDER BY Sales.Customer/Sales.Request_Customer/Sales.Request/Number
```

| LastName |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ Operators and functions in OQL use expressions as inputs to perform mathematical

This document details the use and syntax of expressions in an OQL query.

The domain model used in the various examples is shown below:

{{< figure src="/attachments/refguide/modeling/domain-model/oql/oql-expression-syntax-domain-model.png" >}}

## Data Types

OQL supports a set of data types that differ slightly from [Mendix data types](/refguide/data-types/). The supported data types are:
Expand Down Expand Up @@ -544,7 +548,7 @@ Where `expression` is an expression of any datatype.
The `IS` operator can be used to filter out rows with values that are NULL. For example:

```sql
SELECT Revenue, Cost FROM Sales.Finance WHERE Revenue IS NOT NULL
SELECT Revenue, Cost FROM Sales.Finances WHERE Revenue IS NOT NULL
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo - the other examples used "Finances"

```

| Revenue | Cost |
Expand Down Expand Up @@ -1141,18 +1145,18 @@ For example, a space delimited list can be converted to one with commas to be us
SELECT * FROM Sales.Raw
```

| ID | Import |
| ID | RawImport |
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Import" is an invalid attribute name

|----|-------------------|
| - | "6 D10 machinery" |
| - | "1 A15 tools" |

The text can be converted with `REPLACE` as follows:

```sql
SELECT REPLACE(Import, ' ', ',') FROM Sales.Raw
SELECT REPLACE(RawImport, ' ', ',') FROM Sales.Raw
```

| Import |
| RawImport |
|-------------------|
| "6,D10,machinery" |
| "1,A15,tools" |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ An OQL expression is a query building block that returns a value or a list of va

OQL expressions can be used in `WHERE`, `SELECT`, `GROUP BY`, `UNION`, `HAVING`, and `ON` conditions of `JOIN` clauses. For more information, see [OQL clauses](/refguide/oql-clauses/).

The domain model used in the various examples is shown below:

{{< figure src="/attachments/refguide/modeling/domain-model/oql/oql-expressions-domain-model.png" >}}

## Aggregations{#aggregates}

Aggregations are functions that reduce a list of values from a retrieved column (or columns) into a single value. They can be used in the following ways:
Expand Down Expand Up @@ -173,7 +177,7 @@ SELECT MAX(Stock) as StockMax FROM Sales.Product
To return the name(s) of the product(s) with the highest stock level you have to use a subquery. The subquery returns the maximum stock number, which is then compared to each product's stock in the `WHERE` clause:

```sql
SELECT HighestStockProductName FROM Sales.Product
SELECT Name AS HighestStockProductName FROM Sales.Product
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want to pick up Name here but report it as "HighestStockProductName"

WHERE Stock = (SELECT MAX(P.Stock) FROM Sales.Product P)
```

Expand Down
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about this - what is the relationship between Storage and Location?
I think the example works with this, but not convinced that the example gives a meaningful answer?

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.