Skip to content

Commit 02bb4b9

Browse files
committed
Documentation
1 parent 1dcb048 commit 02bb4b9

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
This log will detail notable changes to MyBatis Dynamic SQL. Full details are available on the GitHub milestone pages.
44

5+
## Release 1.3.0 - Unreleased
6+
7+
### Added
8+
9+
- Added a new sort specification that is useful in selects with joins
10+
11+
512
## Release 1.2.1 - September 29, 2020
613

714
GitHub milestone: [https://github.com/mybatis/mybatis-dynamic-sql/issues?q=milestone%3A1.2.1+](https://github.com/mybatis/mybatis-dynamic-sql/issues?q=milestone%3A1.2.1+)

src/site/markdown/docs/select.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,22 @@ The XML element should look like this:
176176
## Notes on Order By
177177

178178
Order by phrases can be difficult to calculate when there are aliased columns, aliased tables, unions, and joins.
179-
This library has taken a simple approach - the library will either write the column alias or the column
180-
name into the order by phrase. For the order by phrase, the table alias (if there is one) will be ignored.
179+
This library has taken a relatively simple approach:
180+
181+
1. When specifying an SqlColumn in an ORDER BY phrase the library will either write the column alias or the column
182+
name into the ORDER BY phrase. For the ORDER BY phrase, the table alias (if there is one) will be ignored. Use this pattern
183+
when the ORDER BY column is a member of the select list. For example `orderBy(foo)`. If the column has an alias, then
184+
it is easist to use the "arbitrary string" method with the column alias as shown below.
185+
1. It is also possible to explicitly specify a table alias for a column in an ORDER BY phrase. Use this pattern when
186+
there is a join, and the ORDER BY column is in two or more tables, and the ORDER BY column is not in the select
187+
list. For example `orderBy(sortColumn("t1", foo))`.
188+
1. If none of the above use cases meet your needs, then you can specify an arbitrary String to write into the rendered ORDER BY
189+
phrase (see below for an example).
181190

182191
In our testing, this caused an issue in only one case. When there is an outer join and the select list contains
183192
both the left and right join column. In that case, the workaround is to supply a column alias for both columns.
184193

185-
When using a column function (lower, upper, etc.), then is is customary to give the calculated column an alias so you will have a predictable result set. In cases like this there will not be a column to use for an alias. The library supports arbitrary values in an ORDER BY expression like this:
194+
When using a column function (lower, upper, etc.), then it is customary to give the calculated column an alias so you will have a predictable result set. In cases like this there will not be a column to use for an alias. The library supports arbitrary values in an ORDER BY expression like this:
186195

187196
```java
188197
SelectStatementProvider selectStatement = select(substring(gender, 1, 1).as("ShortGender"), avg(age).as("AverageAge"))

0 commit comments

Comments
 (0)