This shows you the differences between two versions of the page.
dev:sql:statements:select:home [2010/07/03 22:40] tdo |
dev:sql:statements:select:home [2016/06/28 22:38] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | {{page>:top_add&nofooter&noeditbtn}} | ||
- | <html><div align="center"><span style="color:red">DRAFT</span></div></html> | ||
- | ====== Omnidex SQL Statement: SELECT ====== | ||
- | {{page>:sql_bar&nofooter&noeditbtn}} | ||
- | ^See Also:^[[dev:sql:statements:select:from |FROM clause]]^[[dev:sql:statements:select:where | WHERE clause ]]^[[dev:sql:statements:select:group_by | GROUP BY clause]]^[[dev:sql:statements:select:order_by | ORDER BY clause ]]^ | ||
- | ===== 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 syntax for the Omnidex SELECT statement is the following: | ||
- | |||
- | <code> | ||
- | SELECT | ||
- | [ < TOP n [ SKIP n ] | EVERY n [ SKIP n ] | RANDOM n | RANDOM (n, seed) > ] | ||
- | [ SAMPLE(‘control_break’ [, ’qualifier’]) ] | ||
- | [ < DISTINCT column_spec | ALL >] | ||
- | select_list | ||
- | FROM data_source | ||
- | [ WHERE criteria_list ] | ||
- | [ GROUP BY group_by_list ] | ||
- | [ HAVING having_list ] | ||
- | [ ORDER BY order_by_list ] | ||
- | [ < UNION [ALL] | INTERSECT | EXCEPT > select_statement ] | ||
- | [ ON [ CURSOR ] cursor_no ] | [ INSTANCE instance_no ] | ||
- | [ WITH option_list ] | ||
- | </code> | ||
- | ==== Select_list syntax: ==== | ||
- | <code> | ||
- | [ * ] | [ 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 ] | ||
- | </code> | ||
- | |||
- | ==== FROM Clause Syntax: ==== | ||
- | <code> | ||
- | 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 ] | ||
- | </code> | ||
- | ==== WHERE Clause Syntax: ==== | ||
- | [[dev:sql:statements:select:where | WHERE Clause Discussion ]] | ||
- | <code> | ||
- | WHERE [ criteria_list ] | ||
- | [ EXISTS (subquery) ] | ||
- | [ IN (subquery) ] | ||
- | </code> | ||
- | ==== GROUP BY/HAVING Clause Syntax: ==== | ||
- | ^[[dev:sql:statements:select:group_by | GROUP BY clause]]^ | ||
- | <code> | ||
- | GROUP BY group_by_columns | ||
- | [ HAVING [ left_operand operator subquery ] | ||
- | [ left_operand IN (subquery) ] ] | ||
- | </code> | ||
- | |||
- | ==== ORDER BY Clause Syntax: ==== | ||
- | [[dev:sql:statements:select:order_by | Order By Discussion ]] | ||
- | <code> | ||
- | ORDER BY [ column_spec | column_position ] [ ASC | DESC ] | ||
- | [, column_spec | column_position ] [ ASC | DESC ] | ||
- | </code> | ||
- | |||
- | ==== WITH Clause Syntax: ==== | ||
- | <code> | ||
- | WITH options | ||
- | </code> | ||
- | |||
- | ===== 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.| | ||
- | |||
- | |||
- | | ||
- | |||
- | ==== GROUP BY Clause ==== | ||
- | ==== HAVING Clause ==== | ||
- | |||
- | |||
- | ==== 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*'; | ||
- | ==== Aggregates, Functions, Expressions ===== | ||
- | |||
- | SELECT customer_no, sum(amount) FROM orders GROUP BY customer_no ORDER BY 2; | ||
- | |||
- | SELECT customer_no, count(distinct order_no) FROM orders GROUP BY customer_no ORDER BY 2, 1; | ||
- | |||
- | ==== Select List Item Ordinal Numbers ==== | ||
- | |||
- | SELECT company, contact, state FROM customers ORDER BY 3; | ||
- | |||
- | SELECT company, contact, state FROM customers ORDER BY 3, 1; | ||
- | |||
- | {{page>:bottom_add&nofooter&noeditbtn}} |