query.select().column("t", "ctx");
query.select().append("CASE WHEN MIN(u.value) IS NOT NULL THEN MIN(u.value) ELSE MIN(b.value) END");
SqlJoinBuilder join = query.from(tableName, "t");
join.leftjoin(bnodes.getName(), "b").on("id", "t.ctx");
join.leftjoin(uris.getShortTableName(), "u").on("id", "t.ctx");
SqlBracketBuilder open = query.filter().and().open();
open.column("u", "value").isNotNull();
open.or();
open.column("b", "value").isNotNull();
open.close();
query.groupBy("t.ctx");
return query.toString();
}