Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 11.0.1 » SQL Anywhere Server - SQL Usage » Query Processing » Query optimization and execution » Semantic query transformations


Elimination of unnecessary DISTINCT conditions

Sometimes a DISTINCT condition is unnecessary. For example, the properties of one or more column in your result may contain a UNIQUE condition, either explicitly or implicitly, because it is a primary key.


The DISTINCT keyword in the following command is unnecessary because the Products table contains the primary key p.ID, which is part of the result set.

FROM Products p;


The database server executes the semantically-equivalent query:

SELECT p.ID, p.Quantity
FROM Products p;

Similarly, the result of the following query contains the primary keys of both tables, so each row in the result must be distinct. So, the database server executes this query without performing DISTINCT on the result set.

FROM SalesOrders o JOIN Customers c
   ON o.CustomerID = c.ID
WHERE c.State = 'NY';

Work[ HF[ c<seq> ] *JH o<seq> ]