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>
Example

XML

Copy
<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 &lt;= <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'
/>
Example
Copy
<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'/>

Select that returns the date of the current day and the date of 7 days ago.

Example
Copy
<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>
 

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>

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>

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>

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>

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>

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>