This is an old revision of the document!


DRAFT

Omnidex SQL Statement: SELECT

Description

The Omnidex SQL Select statement is the primary statement used to query records on Omnidex enhanced data.

Omnidex will automatically optimize the SELECT statement using Omnidex indexes.

Syntax

The concise syntax for the Omnidex SELECT statement is the following:

  SELECT expression_list
      FROM data_source
      [ WHERE clause ]
      [ GROUP BY expression_list ]
          [ HAVING predicates ]
      [ ORDER BY expression_list ]
      [ ON [ CURSOR ] cursor_no ] | [ INSTANCE instance_no ]
      [ WITH options ]

Expression_list syntax:

  expression_list
         [ < TOP (n) 
             [ SKIP(n) | EVERY(n) | RANDOM (n [, seed] ) ] ]
         [ < DISTINCT column_spec | ALL >]
         [ SAMPLE(‘control_break’ [, ’qualifier’]) ] 
         [ UNION [ALL] | INTERSECT | EXCEPT ]
         [ * ] | [ column_spec [column_alias] [, column_spec ... ]
         [ (subquery) ]
         [ aggregate_function( column_spec ) [column_alias] ]
         [ function( column_spec ) ]
         [ column_spec < + | - | / | * > <column_spec | value > [column_alias] ]
         [ $uniquekey | $odxid ]
         

FROM Clause Syntax:

  FROM table_spec [ table_alias ] [, [table_spec2 [ table_alias ] [ $omnidex ] ]
           [[ < LEFT | RIGHT >][ OUTER | CROSS ] ]
       [ JOIN table_spec2 ]
           [ ON table_spec1.linkfield = table_spec2.linkfield ]
           [ <AND | OR> NOT] table_spec.linkfield = table_spec.linkfield ]

WHERE Clause Syntax:

  WHERE [ criteria_list ]
        [ EXISTS (subquery) ]
        [ IN (subquery) ]

GROUP BY/HAVING Clause Syntax:

  GROUP BY group_by_columns
      [ HAVING [ left_operand operator subquery ]
             [ left_operand IN (subquery) ] ]

ORDER BY Clause Syntax:

  ORDER BY [ column_spec | column_position ] [ ASC | DESC ] 
           [, column_spec | column_position ] [ ASC | DESC ]

WITH Clause Syntax:

  WITH options

Discussion

Expression_list

The expression_list can be one of the following:

* All columns for the named tables using a syntax of [/[ database. ] table. ]] *
column_spec A column optionally qualified by a database and table with an optional column_alias.
(subquery) A nested subquery that returns a single select item.
expression A standard SQL or Omnidex-specific function
$uniquekey
$odxid

FROM Clause

The From Datasource can be one of the following:

table_spec A table using a syntax of [database.]table.
$OMNIDEX An internal table automatically created and used for testing consisting of one row and one column.
(subquery) A nested subquery.
JOIN Clause Joins one or more tables.

WHERE Clause

The WHERE clause can be used to specify both criteria and table join information.

select * from trans_table where state = 'CA';

GROUP BY Clause

HAVING Clause

ORDER BY Clause

The ORDER BY clause returns selected rows in ascending or descending order by the specified column_spec or the ordinal position of a column_spec in the column list.

select trans_date, trans_amount from trans_table order by trans_date;
select trans_date, trans_amount from trans_table order by 2;

The column_spec can be in the format of [database.][table.]column or table_alias.column.

select trans_date, trans_amount from trans_table order by db1.trans_table.trans_amount;

Column_spec can also be prefixed with an alias name of the table's column or an alias name of an expression.

select trans_date, trans_amount - discount NetAmount from trans_table order by NetAmount;

The ASC/DESC modifier can be used to return the data in ascending or descending order with ascending order being the default.

select trans_date, trans_amount from trans_table order by trans_date desc;

WITH options

PRESERVE_CRITERIA
PRESERVE_CRITERIA_ORDER

Examples

Select all columns from table

> select * from mytable

Select with Omnidex criteria on Quicktext column

> select company, contact from mytable where company = 'inform*';
 
Back to top
dev/sql/statements/select/home.1278045712.txt.gz · Last modified: 2016/06/28 22:38 (external edit)