# SupportSQLiteQueryBuilder

# SupportSQLiteQueryBuilder

Artifact:[androidx.sqlite:sqlite](https://developer.android.com/jetpack/androidx/releases/sqlite)  
[View Source](https://cs.android.com/search?q=file:androidx/sqlite/db/SupportSQLiteQueryBuilder.android.kt+class:androidx.sqlite.db.SupportSQLiteQueryBuilder)  
Added in[2.0.0](https://developer.android.com/jetpack/androidx/releases/sqlite#2.0.0)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteQueryBuilder "View this page in Java")
Android/JVM
  - android  

  ```
  class SupportSQLiteQueryBuilder
  ```

*** ** * ** ***

A simple query builder to create SQL SELECT queries.

## Summary

|                                              ### Public companion functions                                              |
|--------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------|
| [SupportSQLiteQueryBuilder](https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteQueryBuilder) | [builder](https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteQueryBuilder#builder(kotlin.String))`(tableName: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`)` Creates a query for the given table name. | android |

|                                                   ### Public functions                                                   |
|--------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------|
| [SupportSQLiteQueryBuilder](https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteQueryBuilder) | [columns](https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteQueryBuilder#columns(kotlin.Array))`(columns: `[Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`>?)` Sets the given list of columns as the columns that will be returned.                                                                                    | android |
| [SupportSQLiteQuery](https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteQuery)               | [create](https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteQueryBuilder#create())`()` Creates the[SupportSQLiteQuery](https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteQuery)that can be passed into[SupportSQLiteDatabase.query](https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteDatabase#query(kotlin.String)).                                                              | android |
| [SupportSQLiteQueryBuilder](https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteQueryBuilder) | [distinct](https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteQueryBuilder#distinct())`()` Adds DISTINCT keyword to the query.                                                                                                                                                                                                                                                                                                               | android |
| [SupportSQLiteQueryBuilder](https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteQueryBuilder) | [groupBy](https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteQueryBuilder#groupBy(kotlin.String))`(groupBy: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`?)` Adds a GROUP BY statement.                                                                                                                                                                                                                | android |
| [SupportSQLiteQueryBuilder](https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteQueryBuilder) | [having](https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteQueryBuilder#having(kotlin.String))`(having: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`?)` Adds a HAVING statement.                                                                                                                                                                                                                     | android |
| [SupportSQLiteQueryBuilder](https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteQueryBuilder) | [limit](https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteQueryBuilder#limit(kotlin.String))`(limit: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`)` Adds a LIMIT statement.                                                                                                                                                                                                                          | android |
| [SupportSQLiteQueryBuilder](https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteQueryBuilder) | [orderBy](https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteQueryBuilder#orderBy(kotlin.String))`(orderBy: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`?)` Adds an ORDER BY statement.                                                                                                                                                                                                               | android |
| [SupportSQLiteQueryBuilder](https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteQueryBuilder) | [selection](https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteQueryBuilder#selection(kotlin.String,kotlin.Array))`(selection: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`?, bindArgs: `[Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`?>?)` Sets the arguments for the WHERE clause. | android |

## Public companion functions

### builder

android  
Added in[2.3.0](https://developer.android.com/jetpack/androidx/releases/sqlite#2.3.0)  

```
fun builder(tableName: String): SupportSQLiteQueryBuilder
```

Creates a query for the given table name.  

|                                           Parameters                                           |
|------------------------------------------------------------------------------------------------|-----------------------------|
| `tableName: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | The table name(s) to query. |

|                                                         Returns                                                          |
|--------------------------------------------------------------------------------------------------------------------------|------------------------------|
| [SupportSQLiteQueryBuilder](https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteQueryBuilder) | A builder to create a query. |

## Public functions

### columns

android  
Added in[2.0.0](https://developer.android.com/jetpack/androidx/releases/sqlite#2.0.0)  

```
fun columns(columns: Array<String>?): SupportSQLiteQueryBuilder
```

Sets the given list of columns as the columns that will be returned.  

|                                                                                     Parameters                                                                                     |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------|
| `columns: `[Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`>?` | The list of column names that should be returned. |

|                                                         Returns                                                          |
|--------------------------------------------------------------------------------------------------------------------------|------|
| [SupportSQLiteQueryBuilder](https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteQueryBuilder) | this |

### create

android  
Added in[2.0.0](https://developer.android.com/jetpack/androidx/releases/sqlite#2.0.0)  

```
fun create(): SupportSQLiteQuery
```

Creates the[SupportSQLiteQuery](https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteQuery)that can be passed into[SupportSQLiteDatabase.query](https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteDatabase#query(kotlin.String)).  

|                                                  Returns                                                   |
|------------------------------------------------------------------------------------------------------------|-------------|
| [SupportSQLiteQuery](https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteQuery) | a new query |

### distinct

android  
Added in[2.0.0](https://developer.android.com/jetpack/androidx/releases/sqlite#2.0.0)  

```
fun distinct(): SupportSQLiteQueryBuilder
```

Adds DISTINCT keyword to the query.  

|                                                         Returns                                                          |
|--------------------------------------------------------------------------------------------------------------------------|------|
| [SupportSQLiteQueryBuilder](https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteQueryBuilder) | this |

### groupBy

android  
Added in[2.0.0](https://developer.android.com/jetpack/androidx/releases/sqlite#2.0.0)  

```
fun groupBy(groupBy: String?): SupportSQLiteQueryBuilder
```

Adds a GROUP BY statement.  

|                                           Parameters                                            |
|-------------------------------------------------------------------------------------------------|--------------------------------------|
| `groupBy: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`?` | The value of the GROUP BY statement. |

|                                                         Returns                                                          |
|--------------------------------------------------------------------------------------------------------------------------|------|
| [SupportSQLiteQueryBuilder](https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteQueryBuilder) | this |

### having

android  
Added in[2.0.0](https://developer.android.com/jetpack/androidx/releases/sqlite#2.0.0)  

```
fun having(having: String?): SupportSQLiteQueryBuilder
```

Adds a HAVING statement. You must also provide[groupBy](https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteQueryBuilder#groupBy(kotlin.String))for this to work.  

|                                           Parameters                                           |
|------------------------------------------------------------------------------------------------|--------------------|
| `having: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`?` | The having clause. |

|                                                         Returns                                                          |
|--------------------------------------------------------------------------------------------------------------------------|------|
| [SupportSQLiteQueryBuilder](https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteQueryBuilder) | this |

### limit

android  
Added in[2.0.0](https://developer.android.com/jetpack/androidx/releases/sqlite#2.0.0)  

```
fun limit(limit: String): SupportSQLiteQueryBuilder
```

Adds a LIMIT statement.  

|                                         Parameters                                         |
|--------------------------------------------------------------------------------------------|------------------|
| `limit: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | The limit value. |

|                                                         Returns                                                          |
|--------------------------------------------------------------------------------------------------------------------------|------|
| [SupportSQLiteQueryBuilder](https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteQueryBuilder) | this |

### orderBy

android  
Added in[2.0.0](https://developer.android.com/jetpack/androidx/releases/sqlite#2.0.0)  

```
fun orderBy(orderBy: String?): SupportSQLiteQueryBuilder
```

Adds an ORDER BY statement.  

|                                           Parameters                                            |
|-------------------------------------------------------------------------------------------------|-------------------|
| `orderBy: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`?` | The order clause. |

|                                                         Returns                                                          |
|--------------------------------------------------------------------------------------------------------------------------|------|
| [SupportSQLiteQueryBuilder](https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteQueryBuilder) | this |

### selection

android  
Added in[2.0.0](https://developer.android.com/jetpack/androidx/releases/sqlite#2.0.0)  

```
fun selection(selection: String?, bindArgs: Array<Any?>?): SupportSQLiteQueryBuilder
```

Sets the arguments for the WHERE clause.  

|                                                                                   Parameters                                                                                   |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------|
| `selection: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`?`                                                                              | The list of selection columns                             |
| `bindArgs: `[Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`?>?` | The list of bind arguments to match against these columns |

|                                                         Returns                                                          |
|--------------------------------------------------------------------------------------------------------------------------|------|
| [SupportSQLiteQueryBuilder](https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteQueryBuilder) | this |