@@ -135,15 +135,16 @@ SelectStatementProvider selectStatement = select(itemMaster.allColumns())
135
135
.where(exists(
136
136
select(orderLine. allColumns())
137
137
.from(orderLine, " ol" )
138
- .where(orderLine. itemId, isEqualTo(itemMaster. itemId. qualifiedWith( " im " ) ))
138
+ .where(orderLine. itemId, isEqualTo(itemMaster. itemId))
139
139
))
140
140
.orderBy(itemMaster. itemId)
141
141
.build()
142
142
.render(RenderingStrategies . MYBATIS3 );
143
143
```
144
144
145
- Note that we have to apply the qualifier for the outer query ("im") to the inner query. The qualifier
146
- for the inner query ("ol") is automatically applied.
145
+ Note that the qualifier for the outer query ("im") is automatically applied to the inner query, as well as the
146
+ qualifier for the inner query ("ol"). Carrying alias from an outer query to an inner query is only supported with
147
+ exists or not exists sub queries.
147
148
148
149
An example of a column based subquery is as follows:
149
150
@@ -168,25 +169,29 @@ An example of an exists subquery is as follows:
168
169
``` kotlin
169
170
val selectStatement = select(ItemMaster .allColumns()) {
170
171
from(ItemMaster , " im" )
171
- where(exists {
172
- select(OrderLine .allColumns()) {
173
- from(OrderLine , " ol" )
174
- where(OrderLine .itemId, isEqualTo(ItemMaster .itemId.qualifiedWith(" im" )))
175
- }
176
- })
177
- orderBy(ItemMaster .itemId)
172
+ where {
173
+ exists {
174
+ select(OrderLine .allColumns()) {
175
+ from(OrderLine , " ol" )
176
+ where { OrderLine .itemId isEqualTo ItemMaster .itemId }
177
+ }
178
+ }
179
+ orderBy(ItemMaster .itemId)
180
+ }
178
181
}
179
182
```
180
183
181
184
An example of a column based subquery is as follows:
182
185
``` kotlin
183
186
val selectStatement = select(id, firstName, lastName, birthDate, employed, occupation, addressId) {
184
187
from(Person )
185
- where(id, isEqualTo {
186
- select(max(id)) {
187
- from(Person )
188
- }
189
- })
188
+ where {
189
+ id isEqualTo {
190
+ select(max(id)) {
191
+ from(Person )
192
+ }
193
+ }
194
+ }
190
195
}
191
196
```
192
197
@@ -241,12 +246,12 @@ with the select DSL. You can write subqueries like this:
241
246
242
247
``` kotlin
243
248
val updateStatement = update(Person ) {
244
- set(addressId). equalToQueryResult {
249
+ set(addressId) equalToQueryResult {
245
250
select(add(max(addressId), constant<Int >(" 1" ))) {
246
251
from(Person )
247
252
}
248
253
}
249
- where(id, isEqualTo( 3 ))
254
+ where { id isEqualTo 3 }
250
255
}
251
256
```
252
257
@@ -289,12 +294,12 @@ val selectStatement =
289
294
from {
290
295
select(id, firstName) {
291
296
from(Person )
292
- where(id, isLessThan( 22 ))
297
+ where { id isLessThan 22 }
293
298
orderBy(firstName.descending())
294
299
}
295
300
}
296
- where( rowNum, isLessThan( 5 ))
297
- and ( firstName, isLike( " %a%" ))
301
+ where { rowNum isLessThan 5 }
302
+ and { firstName isLike " %a%" }
298
303
}
299
304
```
300
305
@@ -307,13 +312,13 @@ val selectStatement =
307
312
from {
308
313
select(id, firstName) {
309
314
from(Person , " a" )
310
- where(id, isLessThan( 22 ))
315
+ where { id isLessThan 22 }
311
316
orderBy(firstName.descending())
312
317
}
313
318
+ " b"
314
319
}
315
- where( rowNum, isLessThan( 5 ))
316
- and ( firstName, isLike( " %a%" ))
320
+ where { rowNum isLessThan 5 }
321
+ and { firstName isLike " %a%" }
317
322
}
318
323
```
319
324
@@ -356,15 +361,17 @@ val selectStatement = select(OrderLine.orderId, OrderLine.quantity,
356
361
ItemMaster .itemId.qualifiedWith(" im" ), ItemMaster .description) {
357
362
from(OrderMaster , " om" )
358
363
join(OrderLine , " ol" ) {
359
- on(OrderMaster .orderId, equalTo( OrderLine .orderId))
364
+ on(OrderMaster .orderId) equalTo OrderLine .orderId
360
365
}
361
- leftJoin({
362
- select(ItemMaster .allColumns()) {
363
- from(ItemMaster )
364
- }
365
- + " im"
366
- }) {
367
- on(OrderLine .itemId, equalTo(ItemMaster .itemId.qualifiedWith(" im" )))
366
+ leftJoin(
367
+ {
368
+ select(ItemMaster .allColumns()) {
369
+ from(ItemMaster )
370
+ }
371
+ + " im"
372
+ }
373
+ ) {
374
+ on(OrderLine .itemId) equalTo (ItemMaster .itemId qualifiedWith " im" )
368
375
}
369
376
orderBy(OrderLine .orderId, ItemMaster .itemId)
370
377
}
0 commit comments