Login ProductsSalesSupportDownloadsAbout |
Home » Technical Support » ElevateDB Technical Support » Product Manuals » ElevateDB Version 2 SQL Manual » DML Statements » SELECT |
SELECT [ALL|DISTINCT] *|<SelectColumn> [,<SelectColumn>] [INTO <OutputParameter>[,<OutputParameter>]] [FROM <SelectTable> [<Join> [,<Join>]|,<SelectTable>]] [WHERE <FilterCondition>] [GROUP BY <GroupColumn> [,<GroupColumn>]] [HAVING <GroupFilterCondition>] [UNION| UNION ALL| INTERSECT| INTERSECT ALL| EXCEPT| EXCEPT ALL <QueryExpression>] [ORDER BY <OrderColumn> [,<OrderColumn>]] [RANGE <Start> [TO <End>]] [NOJOINOPTIMIZE] [JOINOPTIMIZECOSTS] [JOININDEXTHRESHHOLD <ThreshholdPercent>] <SelectColumn> = <ColumnExpression> [AS <ColumnCorrelationName>] <SelectTable> = <TableName>|<ViewName>|<DerivedTable> [AS <TableCorrelationName>] <DerivedTable> = (<SELECT Statement>) <Join> = [INNER|[LEFT|RIGHT OUTER] JOIN <SelectTable> ON <JoinCondition> <GroupColumn> = <ColumnExpression> [COLLATE <CollationName>] <OrderColumn> = <ColumnExpression> [COLLATE <CollationName>] [[ASC|ASCENDING]|[DESC|DESCENDING]] <Start> = INTEGER <End> = INTEGER <ThreshholdPercent> = INTEGER
Expression
<AggregateFunction> OF <ColumnName>|ALL
Join Clause | Description |
INNER JOIN | An INNER join specifies that any rows output into the result set from the target table of the join must match the join expression specified in the join expression. If any row from the target table does not match the join expression, then it is discarded. |
LEFT OUTER JOIN | A LEFT OUTER join specifies that any rows output into the result set from the target table of the join must match the join expression specified in the join expression. If any row from the target table does not match the join expression, then NULL values are generated for all column references to the target table in the SELECT column list. |
RIGHT OUTER JOIN | A RIGHT OUTER join is the exact opposite of a LEFT OUTER JOIN and specifies that any rows output into the result set from the source table of the join must match the join expression specified in the join expression. If any row from the source table does not match the join expression, then NULL values are generated for all column references to the source table in the SELECT column list. |
Clause | Description |
UNION | Outputs the rows of both query expressions into the result set. |
INTERSECT | Outputs the rows of the first query expression that match the rows of the second query expression into the result set. |
EXCEPT | Outputs the rows of the first query expression that do not match the rows of the seoncd query expressions into the result set. |
SELECT * FROM Orders RANGE ? TO ?
-- This SELECT statement selects several columns -- from the OrderItems table along with an expression -- for computing the extended price of an ordered item SELECT OrderNo, LineNo, ItemNo, QtyOrdered, UnitPrice, (QtyOrdered * UnitPrice) AS ExtendedPrice FROM OrderItems -- This SELECT statement selects all columns -- from the Orders and OrderItems tables -- joined on the OrderNo column. Note that -- this statement will not output any rows -- into the result set for any rows in the -- Orders table that do not have a corresponding -- row in the OrderItems table SELECT Orders.*, OrderItems.* FROM Orders INNER JOIN OrderItems ON Orders.OrderNo = OrderItems.OrderNo -- This SELECT statement solves the previous -- issue with missing OrderItems rows by using -- a LEFT OUTER JOIN instead. If a corresponding -- row does not exist in the OrderItems table -- for a given Orders row, then the Orders row -- will still be included and NULL values will -- be output for all OrderItems columns SELECT Orders.*, OrderItems.* FROM Orders LEFT OUTER JOIN OrderItems ON Orders.OrderNo = OrderItems.OrderNo -- This SELECT statement outputs all rows from -- the Customers table where the customer has -- not placed an order within the last year SELECT * FROM Customers WHERE NOT EXISTS (SELECT * FROM Orders WHERE CustNo=Customers.CustNo AND OrderDate BETWEEN (CURRENT_DATE - INTERVAL '1' YEAR) AND CURRENT_DATE) -- This SELECT statement outputs all customers -- and their total orders for the last year in -- descending order by the TotalOrdersAmount -- SELECT column expression SELECT Customer.CustNo, Customer.Name, COUNT(Orders.*) AS TotalOrders, SUM(OrderItems.QtyOrdered * OrderItems.UnitPrice) AS TotalOrdersAmount FROM Customers INNER JOIN Orders ON Customer.CustNo = Orders.CustNo INNER JOIN OrderItems ON Orders.OrderNo = OrderItems.OrderNo WHERE Orders.OrderDate BETWEEN (CURRENT_DATE - INTERVAL '1' YEAR) AND CURRENT_DATE) GROUP BY Customer.CustNo, Customer.Name ORDER BY TotalOrdersAmount DESC -- This SELECT statement selects the total orders -- from the Orders table for all rows where the -- OrderDate is in January and uses the UNION -- clause to append the total orders from the Orders -- table where the OrderDate is in February SELECT 'January' AS OrderMonth, SUM(OrderItems.QtyOrdered * OrderItems.UnitPrice) AS TotalOrdersAmount FROM Orders INNER JOIN OrderItems ON Orders.OrderNo = OrderItems.OrderNo WHERE Orders.OrderDate BETWEEN DATE '2006-01-01' AND DATE '2006-01-31' UNION ALL SELECT 'February' AS OrderMonth, SUM(OrderItems.QtyOrdered * OrderItems.UnitPrice) AS TotalOrdersAmount FROM Orders INNER JOIN OrderItems ON Orders.OrderNo = OrderItems.OrderNo WHERE Orders.OrderDate BETWEEN DATE '2006-02-01' AND DATE '2006-02-28' -- This SELECT statement returns the -- user-defined version for a given -- table, or NULL if the table does -- not exist. It uses the INTO clause -- to put the resultant value into an -- output parameter. SELECT Version INTO :Version FROM Information.Tables WHERE Name=:Name
Deviation | Details |
Recursive Queries | ElevateDB does not support recursive queries. |
Sampling | ElevateDB does not support sampling in SELECT statements. |
FULL OUTER JOINS | ElevateDB does not support FULL OUTER JOINs. |
NATURAL JOINS | ElevateDB does not support NATURAL JOINs. |
USING | ElevateDB does not support the USING clause in joins. |
CUBE and ROLLUP | ElevateDB does not support the CUBE and ROLLUP clauses in the GROUP BY clause. |
GROUPING SETS | ElevateDB does not support the GROUPING SETS clause in the GROUP BY clause. |
GROUP BY DISTINCT | ElevateDB does not support the DISTINCT clause in the GROUP BY clause. |
WINDOW | ElevateDB does not support the WINDOW clause. |
CORRESPONDING BY | ElevateDB does not support the CORRESPONDING BY clause in the UNION, INTERSECT, and EXCEPT set operators. |
RANGE | The RANGE clause is an ElevateDB extension. |
This web page was last updated on Thursday, November 16, 2023 at 10:39 AM | Privacy PolicySite Map © 2024 Elevate Software, Inc. All Rights Reserved Questions or comments ? E-mail us at info@elevatesoft.com |