The SELECT statement is used to obtain values from a database. A SELECT operation is called query. Rows or values that meet a specific search criteria for a query are called qualified rows or values. What a query returns is called result set.
1 Select
This tag allows you to describe in the abstract (independent of the DBMS) SELECT operations.
<select
first='first'
skip='skip'
intotemp='intotemp'
log='y|yes'
oracle='ansi'
ansi='yes'
prepare='false'
iwa-accelerate='on|off'
iwa-fallback='on|off'
>
<optimizer-directives /> *
<columns> !
<cols> +
</columns>
<from
table='table'
type='left'
alias='alias'
if-has-security-role='true'
> !
<join
table='table'
type='left'
alias='alias'
if-has-security-role='true'
> *
<on> +
<join_tables_condition> +
</on>
</join>
<lateral alias='alias'> *
<select> +
</lateral>
</from>
<columns> !
<cols> +
</columns>
<where> ?
<condition> !
</where>
<group> ?
<groupby> !
</group>
<having> ?
<having> !
</having>
<order> ?
<orderby> !
</order>
<orderofobject /> ?
</select>
Attributes | |||||
---|---|---|---|---|---|
Name | Type | Required | Default | Description | |
Afirst | integer | Indicates that only the first 'n' rows (as indicated in the attribute) that meet the selection conditions are selected. | |||
Askip | integer | Indicates that only the first 'n' rows (as indicated in the attribute) that meet the selection conditions are skipped. | |||
Aintotemp | string | If the result of the selection is to be sent to a temporary table, the desired name for the table can be indicated in this attribute. | |||
Alog | string | If the intotemp attribute is informed that, by default, the temporary tables are created without log ('' 'WITH NO LOG' ''), in case the table requires log this attribute is reported. | |||
Aoracle | string | You can indicate if you want Oracle to generate the syntax in ANSI format instead of in Oracle grammar. It is used when in a SELECT of Oracle grammar there is a table in a LEFT JOIN that in turn is linked to another FROM table, since this circumstance is not allowed in Oracle grammar. | |||
Aansi | string | You can indicate if you want the syntax to be generated in ANSI format. | |||
Aprepare | boolean | In an XSQL script, it prevents the SELECT from being prepared and it is sent directly to the engine. | |||
Aiwa-accelerate | string | on to indicate that this and subsequent statements of the session are attempted to be executed on the IWA accelerator. off to deactivate the acceleration attempt using IWA. | |||
Aiwa-fallback | string | off indicates that the select statement must be executed in an IWA accelerator and for this the iwa-accelerate parameter must have the value on. If the sentence cannot be accelerated, an error is returned. With this mode, you only try to accelerate the active statement, deactivating the acceleration for the rest of the following statements. |
Arguments | |||||
---|---|---|---|---|---|
Name | Type | Required | Unique | Nullable | Description |
Eoptimizer-directives | It allows to indicate optimization directives according to the database engine. See section Optimization Directives. | ||||
Ecolumns | List of columns to select separated by comma. | ||||
Vcols | string | ||||
Efrom | Indicates which is the main table of the SELECT. | ||||
Atable | string | Table name. | |||
Atype | string | Indicates the type of link. This can be a normal link or a LEFT JOIN type link. If nothing is indicated, by default the link is of the INNER JOIN type, so this attribute would only be necessary to indicate that the link is of the LEFT JOIN type (OUTER in Informix, LEFT JOIN in DB2, (+) in Oracle). | |||
Aalias | string | Table alias. | |||
Aif-has-security-role | boolean | It indicates that this join is only carried out in case an SQL restriction is established for the user on the database in which it is executed. If it is used in an XSQL-Script program, it is necessary that the select has the attribute secure='true'. Otherwise, the join is always done. | |||
Ejoin | Specify the tables related to the join. | ||||
Atable | string | Table name. | |||
Atype | string | Indicates the type of link. This can be a normal link or a LEFT JOIN type link. If nothing is indicated, by default the link is of the INNER JOIN type, so this attribute would only be necessary to indicate that the link is of the LEFT JOIN type (OUTER in Informix, LEFT JOIN in DB2, (+) in Oracle). | |||
Aalias | string | Table alias. | |||
Aif-has-security-role | boolean | It indicates that this join is only carried out in case an SQL restriction is established for the user on the database in which it is executed. If it is used in an XSQL-Script program, it is necessary that the select has the attribute secure='true'. Otherwise, the join is always done. | |||
Eon | |||||
Vjoin_tables_condition | string | ||||
Elateral | Specify lateral join select. | ||||
Aalias | Select alias. | ||||
Vselect | string | ||||
Ecolumns | List of columns to select separated by comma. | ||||
Vcols | string | ||||
Ewhere | Indicate non-link conditions between tables. | ||||
Vcondition | string | ||||
Egroup | |||||
Vgroupby | string | ||||
Ehaving | |||||
Vhaving | string | ||||
Eorder | |||||
Vorderby | string | ||||
Eorderofobject | It is useful in sqltables to indicate that the order of the records is equal to that established for the main select of the object. |
XML
<select> <columns> gcom_presupm.codnac, gcom_presupm.delega, gcom_presupm.tercer, gcom_presupm.codfam </columns> <from table='gcom_presupt'> <join table='gcom_presupm'> <on>gcom_presupt.codigo = gcom_presupm.tippre</on> </join> </from> <where> gcom_presupm.preid = <p_preid /> AND gcom_presupm.numrev <= <p_numrev /> </where> </select>
Blob type field selection
When a blob type field is selected, it is necessary to include the primary key field or the rowid to be able to retrieve it when needed.
2 Tag rowid
This tag is used within the <columns> tag to add the rowid of the indicated table to the selected columns. The name of the table from which to select the rowid must be indicated using the table or if-physical-table attributes.
<rowid
table='table'
if-physical-table='if-physical-table'
/>
Attributes | |||||
---|---|---|---|---|---|
Name | Type | Required | Default | Description | |
Atable | string | Name of the table from which the rowid must be selected. | |||
Aif-physical-table | string | Name of the table from which the rowid must be selected if the table is a physical table, that is, it is not a view or a synonym. If the table is not physical, a virtual column with value 0 is added. |
<select> <columns><rowid table='cdiarios' />, *</columns> <from table='cdiarios' /> </select>
2.1 Usage examples of 'if-physical-table' attribute
3 Select-one
This tag is used to query a database that returns a single record of several columns made up of constant values.
<select-one values='values'/>
Attributes | |||||
---|---|---|---|---|---|
Name | Type | Required | Default | Description | |
Avalues | string | Comma Separated Values. |
Select that returns the date of the current day and the date of 7 days ago.
<select-one><today/>,<eval-date d='-7'><today/></eval-date></select-one>
4 Union
This tag is used to perform several concatenated SQL queries. The 'union' tag would be like the root tag that encapsulates the select statements.
<union
type='type'
intotemp='intotemp'
log='y|yes'
iwa-accelerate='on|off'
iwa-fallback='on|off'
>
<select /> +
</union>
Attributes | |||||
---|---|---|---|---|---|
Name | Type | Required | Default | Description | |
Atype | string | It indicates if the union is of type all, that is to say, if it is UNION ALL. | |||
Aintotemp | string | If the result of the selection is to be sent to a temporary table, the desired name for the table can be indicated in this attribute. | |||
Alog | string | If the 'intotemp' attribute is informed that by default the temporary tables are created without log ('' 'WITH NO LOG' ''), in case table requires log this attribute should be reported. | |||
Aiwa-accelerate | string | on to indicate that this statement and the following of the session are attempted to execute on the IWA accelerator. off to deactivate the acceleration attempt using IWA. | |||
Aiwa-fallback | string | off indicates that the select statement must be executed in an IWA accelerator. In this case, the iwa-accelerate parameter must have the value on. If the sentence cannot be accelerated, an error is returned. With this mode, you only try to accelerate the active statement, deactivating the acceleration for the rest of the following sentences. |
Arguments | |||||
---|---|---|---|---|---|
Name | Type | Required | Unique | Nullable | Description |
Eselect | See select section. |
5 Optimization Directives
These are a series of tags that allow you to indicate which optimization policy to use for each database engine. They are used for statements of type select, update and delete.
5.1 ids-directive
It allows to indicate optimization directives for the execution SQL statement in a database with ids engine.
<ids-directive>
<value /> +
</ids-directive>
Arguments | |||||
---|---|---|---|---|---|
Name | Type | Required | Unique | Nullable | Description |
Evalue | Optimization directive for databases ids. |
5.2 oracle-directive
It allows to indicate optimization directives for the execution SQL statement in a database with oracle engine.
<oracle-directive>
<value /> +
</oracle-directive>
Arguments | |||||
---|---|---|---|---|---|
Name | Type | Required | Unique | Nullable | Description |
Evalue | Optimization directive for databases Oracle. |
5.3 db2u-directive
It allows to indicate optimization directives for the execution SQL statement in a database with engine db2u.
<db2u-directive>
<value /> +
</db2u-directive>
Arguments | |||||
---|---|---|---|---|---|
Name | Type | Required | Unique | Nullable | Description |
Evalue | Optimization directive for databases db2u. |
5.4 db2i-directive
It allows to indicate optimization directives for the execution SQL statement in a database with engine db2i.
<db2i-directive>
<value /> +
</db2i-directive>
Arguments | |||||
---|---|---|---|---|---|
Name | Type | Required | Unique | Nullable | Description |
Evalue | Optimization directive for databases db2i. |
5.5 mysql-directive
It allows to indicate optimization directives for the execution SQL statement in a database with mysql engine.
<mysql-directive>
<value /> +
</mysql-directive>
Arguments | |||||
---|---|---|---|---|---|
Name | Type | Required | Unique | Nullable | Description |
Evalue | Optimization directive for databases mysql. |
5.6 postgres-directive
It allows to indicate optimization directives for the execution SQL statement in a database with postgres engine.
<postgres-directive>
<value /> +
</postgres-directive>
Arguments | |||||
---|---|---|---|---|---|
Name | Type | Required | Unique | Nullable | Description |
Evalue | Optimization directive for databases postgres. |