# QBColumn

## Overview

The `QBColumn` class represents a column in a `QBSelect` query. It is used to define conditions, aggregate functions, and transformations within queries. The class provides a range of properties and methods for handling column-specific operations such as mathematical expressions, sorting, and conditional comparisons.

Columns are typed based on their definition in the database, in situations where the type is unknown a [QBGenericColumn](https://docs.servoy.com/reference/servoycore/dev-api/database-manager/qbgenericcolumn) is returned by the methods. That class contains all methods and properties that are defined in any of the type-specific column classes.

Key properties include `abs`, `ceil`, and `floor` for mathematical transformations, and `avg`, `count`, and `sum` for aggregate functions. Sorting can be applied using `asc` and `desc`, while date manipulations are supported with properties like `day`, `month`, and `year`.

Methods enable additional functionality, including comparisons (`eq`, `between`, `like`), mathematical operations (`plus`, `minus`, `mod`), and string manipulations (`substring`, `concat`). The `parent` and `root` properties provide access to the query's structure, supporting complex query building and integration.

For more information about constructing and executing queries, refer to the [QBSelect](https://docs.servoy.com/reference/servoycore/dev-api/database-manager/qbselect) section of this documentation.

## Properties Summarized

| Type                                                                                       | Name              | Summary                               |
| ------------------------------------------------------------------------------------------ | ----------------- | ------------------------------------- |
| [QBSort](/reference/servoycore/dev-api/database-manager/qbsort.md)                         | [asc](#asc)       | Create an ascending sort expression   |
| [QBCountAggregate](/reference/servoycore/dev-api/database-manager/qbcountaggregate.md)     | [count](#count)   | Create an aggregate count expression. |
| [QBSort](/reference/servoycore/dev-api/database-manager/qbsort.md)                         | [desc](#desc)     | Create a descending sort expression   |
| [QBCondition](/reference/servoycore/dev-api/database-manager/qbcondition.md)               | [isNull](#isnull) | Compare column with null.             |
| [QBColumn](/reference/servoycore/dev-api/database-manager/qbcolumn.md)                     | [max](#max)       | Create an aggregate max expression.   |
| [QBColumn](/reference/servoycore/dev-api/database-manager/qbcolumn.md)                     | [min](#min)       | Create an aggregate min expression.   |
| [QBColumnComparable](/reference/servoycore/dev-api/database-manager/qbcolumncomparable.md) | [not](#not)       | Create a negated condition.           |

## Methods Summarized

| Type                                                                                 | Name                                              | Summary                                                                                |
| ------------------------------------------------------------------------------------ | ------------------------------------------------- | -------------------------------------------------------------------------------------- |
| [QBCondition](/reference/servoycore/dev-api/database-manager/qbcondition.md)         | [between(value1, value2)](#between-value1-value2) | Compare column to a range of 2 values or other columns.                                |
| [QBGenericColumn](/reference/servoycore/dev-api/database-manager/qbgenericcolumn.md) | [cast(type)](#cast-type)                          | Create cast(column, type) expression                                                   |
| [QBColumn](/reference/servoycore/dev-api/database-manager/qbcolumn.md)               | [coalesce(value)](#coalesce-value)                | Create coalesce(arg) expression                                                        |
| [QBTextColumn](/reference/servoycore/dev-api/database-manager/qbtextcolumn.md)       | [concat(value)](#concat-value)                    | Concatenate with value                                                                 |
| [QBCondition](/reference/servoycore/dev-api/database-manager/qbcondition.md)         | [eq(value)](#eq-value)                            | Compare column with a value or another column.                                         |
| [QBCondition](/reference/servoycore/dev-api/database-manager/qbcondition.md)         | [ge(value)](#ge-value)                            | Compare column with a value or another column.                                         |
| [Number](/reference/servoycore/dev-api/js-lib/number.md)                             | [getFlags()](#getflags)                           | The flags are a bit pattern consisting of 1 or more of the following bits: - JSColumn. |
| [String](/reference/servoycore/dev-api/js-lib/string.md)                             | [getTypeAsString()](#gettypeasstring)             | Column type as a string                                                                |
| [QBCondition](/reference/servoycore/dev-api/database-manager/qbcondition.md)         | [gt(value)](#gt-value)                            | Compare column with a value or another column.                                         |
| [QBCondition](/reference/servoycore/dev-api/database-manager/qbcondition.md)         | [isin(query)](#isin-query)                        | Compare column with subquery result.                                                   |
| [QBCondition](/reference/servoycore/dev-api/database-manager/qbcondition.md)         | [isin(values)](#isin-values)                      | Compare column with values.                                                            |
| [QBCondition](/reference/servoycore/dev-api/database-manager/qbcondition.md)         | [isin(customQuery, args)](#isin-customquery-args) | Compare column with custom query result.                                               |
| [QBCondition](/reference/servoycore/dev-api/database-manager/qbcondition.md)         | [le(value)](#le-value)                            | Compare column with a value or another column.                                         |
| [QBCondition](/reference/servoycore/dev-api/database-manager/qbcondition.md)         | [lt(value)](#lt-value)                            | Compare column with a value or another column.                                         |
| [QBColumn](/reference/servoycore/dev-api/database-manager/qbcolumn.md)               | [nullif(arg)](#nullif-arg)                        | Create nullif(arg) expression                                                          |

## Properties Detailed

### asc

Create an ascending sort expression

**Type**\
[QBSort](/reference/servoycore/dev-api/database-manager/qbsort.md) a QBSort representing an ascending sort order.

**Sample**

```js
var query = datasources.db.example_data.orders.createSelect();
query.sort
.add(query.joins.orders_to_order_details.columns.quantity.asc)
.add(query.columns.companyid)
foundset.loadRecords(query)
```

### count

Create an aggregate count expression.

**Type**\
[QBCountAggregate](/reference/servoycore/dev-api/database-manager/qbcountaggregate.md) a QBAggregate representing the count aggregate function.

**Sample**

```js
var query = datasources.db.example_data.orders.createSelect();
	query.groupBy.addPk() // have to group by on pk when using having-conditions in (foundset) pk queries
	.root.having.add(query.joins.orders_to_order_details.columns.quantity.count.eq(0))
	foundset.loadRecords(query)
```

### desc

Create a descending sort expression

**Type**\
[QBSort](/reference/servoycore/dev-api/database-manager/qbsort.md) a QBSort representing a descending sort order.

**Sample**

```js
var query = datasources.db.example_data.orders.createSelect();
query.sort
.add(query.joins.orders_to_order_details.columns.quantity.desc)
.add(query.columns.companyid)
foundset.loadRecords(query)
```

### isNull

Compare column with null.

**Type**\
[QBCondition](/reference/servoycore/dev-api/database-manager/qbcondition.md) a QBCondition representing the "is null" comparison.

**Sample**

```js
query.where.add(query.columns.flag.isNull)
```

### max

Create an aggregate max expression.

**Type**\
[QBColumn](/reference/servoycore/dev-api/database-manager/qbcolumn.md) a QBColumn representing the sum aggregate function.

**Sample**

```js
var query = datasources.db.example_data.orders.createSelect();
	query.groupBy.addPk() // have to group by on pk when using having-conditions in (foundset) pk queries
	.root.having.add(query.joins.orders_to_order_details.columns.quantity.count.max(10))
	foundset.loadRecords(query)
```

### min

Create an aggregate min expression.

**Type**\
[QBColumn](/reference/servoycore/dev-api/database-manager/qbcolumn.md) a QBColumn representing the minimum aggregate function.

**Sample**

```js
var query = datasources.db.example_data.orders.createSelect();
	query.groupBy.addPk() // have to group by on pk when using having-conditions in (foundset) pk queries
	.root.having.add(query.joins.orders_to_order_details.columns.quantity.count.min(10))
	foundset.loadRecords(query)
```

### not

Create a negated condition.

**Type**\
[QBColumnComparable](/reference/servoycore/dev-api/database-manager/qbcolumncomparable.md) a QBColumn representing the negated condition.

**Sample**

```js
query.where.add(query.columns.flag.not.eq(1))
```

## Methods Detailed

### between(value1, value2)

Compare column to a range of 2 values or other columns.

**Parameters**

* [Object](/reference/servoycore/dev-api/js-lib/object.md) **value1** ;
* [Object](/reference/servoycore/dev-api/js-lib/object.md) **value2** ;

**Returns:** [QBCondition](/reference/servoycore/dev-api/database-manager/qbcondition.md) a QBCondition representing the "between" comparison for the two values.

**Sample**

```js
query.where.add(query.columns.flag.between(0, 5))
```

### cast(type)

Create cast(column, type) expression

**Parameters**

* [String](/reference/servoycore/dev-api/js-lib/string.md) **type** string type, see QUERY\_COLUMN\_TYPES

**Returns:** [QBGenericColumn](/reference/servoycore/dev-api/database-manager/qbgenericcolumn.md) a QBGenericColumn representing the column cast to the specified type.

**Sample**

```js
query.result.add(query.columns.mycol.cast(QUERY_COLUMN_TYPES.TYPE_INTEGER))
```

### coalesce(value)

Create coalesce(arg) expression

**Parameters**

* [Object](/reference/servoycore/dev-api/js-lib/object.md) **value** when column is null

**Returns:** [QBColumn](/reference/servoycore/dev-api/database-manager/qbcolumn.md) a QBColumn representing the coalesce expression.

**Sample**

```js
query.result.add(query.columns.mycol.coalesce('defval'))
```

### concat(value)

Concatenate with value

**Parameters**

* [Object](/reference/servoycore/dev-api/js-lib/object.md) **value** value to concatenate with

**Returns:** [QBTextColumn](/reference/servoycore/dev-api/database-manager/qbtextcolumn.md) a QBTextColumn representing the column concatenated with the value.

**Sample**

```js
query.result.add(query.columns.firstname.concat(' ').concat(query.columns.lastname))
```

### eq(value)

Compare column with a value or another column.\
Operator: equals

**Parameters**

* [Object](/reference/servoycore/dev-api/js-lib/object.md) **value** ;

**Returns:** [QBCondition](/reference/servoycore/dev-api/database-manager/qbcondition.md) a QBCondition representing the "equals" comparison.

**Sample**

```js
query.where.add(query.columns.flag.eq(1))
```

### ge(value)

Compare column with a value or another column.\
Operator: greaterThanOrEqual

**Parameters**

* [Object](/reference/servoycore/dev-api/js-lib/object.md) **value** ;

**Returns:** [QBCondition](/reference/servoycore/dev-api/database-manager/qbcondition.md) a QBCondition representing the "greater than or equal to" comparison.

**Sample**

```js
query.where.add(query.columns.flag.ge(2))
```

### getFlags()

The flags are a bit pattern consisting of 1 or more of the following bits:\
\- JSColumn.UUID\_COLUMN\
\- JSColumn.EXCLUDED\_COLUMN\
\- JSColumn.TENANT\_COLUMN

**Returns:** [Number](/reference/servoycore/dev-api/js-lib/number.md) an integer representing the flags of the column.

### getTypeAsString()

Column type as a string

**Returns:** [String](/reference/servoycore/dev-api/js-lib/string.md) a string representing the column type.

### gt(value)

Compare column with a value or another column.\
Operator: greaterThan

**Parameters**

* [Object](/reference/servoycore/dev-api/js-lib/object.md) **value** ;

**Returns:** [QBCondition](/reference/servoycore/dev-api/database-manager/qbcondition.md) a QBCondition representing the "greater than" comparison.

**Sample**

```js
query.where.add(query.columns.flag.gt(0))
```

### isin(query)

Compare column with subquery result.

**Parameters**

* [QBPart](/reference/servoycore/dev-api/database-manager/qbpart.md) **query** subquery

**Returns:** [QBCondition](/reference/servoycore/dev-api/database-manager/qbcondition.md) a QBCondition representing the "in" comparison with a subquery.

**Sample**

```js
query.where.add(query.columns.flag.isin(query2))
```

### isin(values)

Compare column with values.

**Parameters**

* [Array](/reference/servoycore/dev-api/js-lib/array.md) **values** array of values

**Returns:** [QBCondition](/reference/servoycore/dev-api/database-manager/qbcondition.md) a QBCondition representing the "in" comparison with a list of values.

**Sample**

```js
query.where.add(query.columns.flag.isin([1, 5, 99]))
```

### isin(customQuery, args)

Compare column with custom query result.

**Parameters**

* [String](/reference/servoycore/dev-api/js-lib/string.md) **customQuery** custom query
* [Array](/reference/servoycore/dev-api/js-lib/array.md) **args** query arguments

**Returns:** [QBCondition](/reference/servoycore/dev-api/database-manager/qbcondition.md) a QBCondition representing the "in" comparison with a custom query and arguments.

**Sample**

```js
query.where.add(query.columns.ccy.isin("select ccycode from currencies c where c.category = " + query.getTableAlias() + ".currency_category and c.flag = ?", ['T']))
```

### le(value)

Compare column with a value or another column.\
Operator: lessThanOrEqual

**Parameters**

* [Object](/reference/servoycore/dev-api/js-lib/object.md) **value** ;

**Returns:** [QBCondition](/reference/servoycore/dev-api/database-manager/qbcondition.md) a QBCondition representing the "less than or equal to" comparison.

**Sample**

```js
query.where.add(query.columns.flag.le(2))
```

### lt(value)

Compare column with a value or another column.\
Operator: lessThan

**Parameters**

* [Object](/reference/servoycore/dev-api/js-lib/object.md) **value** ;

**Returns:** [QBCondition](/reference/servoycore/dev-api/database-manager/qbcondition.md) a QBCondition representing the "less than" comparison.

**Sample**

```js
query.where.add(query.columns.flag.lt(99))
```

### nullif(arg)

Create nullif(arg) expression

**Parameters**

* [Object](/reference/servoycore/dev-api/js-lib/object.md) **arg** object to compare

**Returns:** [QBColumn](/reference/servoycore/dev-api/database-manager/qbcolumn.md) a QBColumn representing the nullif expression.

**Sample**

```js
query.result.add(query.columns.mycol.nullif('none'))
```

***


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.servoy.com/reference/servoycore/dev-api/database-manager/qbcolumn.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
