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

SAP Sybase SQL Anywhere 16.0 » SQL Anywhere Server - SQL Usage » Queries and data modification » Use of subqueries

 

Single-row and multiple-row subqueries

Subqueries that can return only one or zero rows to the outer statement are called single-row subqueries. Single-row subqueries can be used anywhere in a SQL statement, with or without a comparison operator.

For example, a single-row subquery can be used in an expression in the SELECT clause:

SELECT (select FIRST T.x FROM T) + 1 as ITEM_1, 2 as ITEM_2,...

Alternatively, a single-row subquery can be used in an expression in the SELECT clause with a comparison operator.

For example:

SELECT IF (select FIRST T.x FROM T) >= 10 THEN 1 ELSE 0 ENDIF as ITEM_1, 2 as ITEM_2,...

Subqueries that can return more than one row (but only one column) to the outer statement are called multiple-row subqueries. Multiple-row subqueries are subqueries used with an IN, ANY, ALL, or EXISTS clause.

 Example 1: Single-row subquery
 Example 2: Single-row subquery
 Example 3: Simple multiple-row subquery using IN
 Example 4: Multiple-row subqueries comparing use of IN, ANY, and ALL