Ormlite subquery in select

963 Views Asked by At

How execute subquery in select using Ormlite. I try this

QueryBuilder<Group, Long> queryBuilder = groupDAO.queryBuilder();
            queryBuilder.selectColumns(BaseColumns._ID ,Group.COLUMN_TITLE, "(SELECT relation_type FROM groupmembership as gr WHERE `group`._ID = gr.group_id AND gr.user_id = 687)");

but get exception

java.lang.IllegalArgumentException: Unknown column name '(SELECT relation_type FROM groupmembership as gr WHERE `group`._ID = gr.group_id AND gr.user_id = 687)' in table groups

By the way. I know about rawQuery(), but I want use QueryBuilder

1

There are 1 best solutions below

0
On BEST ANSWER

It is impossible because QueryBuilder.selectColumns() check column names before adding to query.

I found this in source

private void addSelectColumnToList(String columnName) {
    verifyColumnName(columnName);
    selectColumnList.add(columnName);
}