You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/site/markdown/docs/select.md
+12-3Lines changed: 12 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -176,13 +176,22 @@ The XML element should look like this:
176
176
## Notes on Order By
177
177
178
178
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).
181
190
182
191
In our testing, this caused an issue in only one case. When there is an outer join and the select list contains
183
192
both the left and right join column. In that case, the workaround is to supply a column alias for both columns.
184
193
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:
0 commit comments